Disclaimer

This work is very preliminary as I get back into the coding swing of things. Data wrangling and figure generation will be done via R, but the rest of the project will be done using good ol’ microsoft products. This is just an entry point into data crunching and should by no means be considered a final product.

Also, I’m not great at this but whatever. I could automate this, but I’ll figure that out shortly!

Need to update figures & analyze sites for seasonal trends

Methodology

SNOTEL data was provided by the NRCS. Data was cleaned by removing outliers that are likely implausible; any year with more than 15 observations missing was removed. Temperatures were adjusted using the Morrisey method for stations identified by Ma et al (2019) due to SNOTEL temperature sensor changes, with the adjustment applied to pre-sensor change data. Daily mean observations were detrended to determine whether values were increasing or decreasing from the entire time series trend. Daily mean temperatures were first averaged by water year, with all water year means then averaged by day of water year. The mean temperature by day for the period of record was averaged. To find the standard deviation, the daily mean temperatures by water year was subtracted from the averaged mean temperature by day for the period of record. All water year means averaged by day of water year were subtracted from the temperature mean. The resulting values were then added together to find the “residual” of the daily mean temperatures by water year. The standard deviation was then computed from those residuals, with trends analyzed by Mann‐Kendall significance test and Theil‐Sen’s rate of change. Significant trends are identified with p-values of less than 0.10.

Morrisey Method

The Morrisey Method is taken from Ma, Fassnacht and Kampf..

In R script: T(adjusted) = 5.3x10(-7)xT(old)4+3.72x10(-5)xT(old)3-2.16x10(-3)xT(old)2-7.32x10^(-2)xT(old)+1.37

In the Ma et al. spreadsheet, H1 is Morrisey, H2 is Oiler

03/01/2023 update

Analyzing by summer and winter season for each station’s timeseries, using the shifted mean of the time series, then sigmoidal detrending. Standard deviation is taken with the relevant days of the water year.

03/06/2023 update

Analyzing by spring and fall season as well….

San Juan Area SNOTEL sites:

Beartown 327 Original 4/18/2005

Cascade #2 387 Morrisey 6/18/2004

Cumbres Trestle 431 Oyler -> Morrisey 6/8/2005

Idarado 538 Morrisey 7/12/2004

Lone Cone 589 Oyler -> Morrisey 6/22/2005

Middle Creek 624 Morrisey 6/26/2006

Mineral Creek 629 Oyler ?? -> Morrisey 6/22/2004

Molas Lake 632 NSCE-Morrisey, Bias-Original 10/2/2003

Red Mountain Pass 713 Morrisey 8/18/2004

Scotch Creek 739 Morrisey 6/15/2004

Slumgullion 762 Morrisey 6/26/2006

Spud Mountain 780 Morrisey 6/28/2004

Stump Lakes 797 Morrisey 7/22/2005

Upper Rio Grande 839 Oyler -> Morrisey 5/26/2004 *Why is this in red?

Upper San Juan 840 Morrisey 4/7/2004

Vallecito 843 Morrisey 7/22/2005

Wolf Creek Summit 874 Morrisey 7/12/2004

Data from thesis research:


SNOTEL_san_juan_Area <- snotel_download(site_id = c(327, 387, 431, 538, 589, 624, 629, 632, 713, 739, 762, 780, 797, 839, 840, 843, 874), path = tempdir('../data'), internal = TRUE)

write.csv(SNOTEL_san_juan_Area,"C:/Users/13074/Documents/ESS580/thesis_project/San_Juan_area/data_raw/snotel_san_juans.csv", row.names = FALSE) #write in the raw data

Beartown 327

Original

SNOTEL_san_juan_Area <- read.csv("C:/Users/13074/Documents/ESS580/thesis_project/San_Juan_area/data_raw/snotel_san_juans.csv", header = TRUE)

snotel_327 <- SNOTEL_san_juan_Area %>% 
  filter(site_id == "327")
#str(snotel_327) # check the date, usually a character.  

snotel_327$Date <- as.Date(snotel_327$date) #change date from character to date format, capitalize to work with Water year functon from NWIS.

#THIS WILL CHANGE FOR EACH STATION
snotel_327_clean <- snotel_327 %>% # filter for the timeframe
  filter(Date >= "1983-08-10" & Date <= "2022-09-30") %>%
  #filter(temperature_mean >= -30 & temperature_mean <= 20) %>% # removing outliers   
  addWaterYear() %>% 
  mutate(daymonth = format(as.Date(Date), "%d-%m")) %>% 
  na.omit()

#adding water day using difftime (SUPER COOL. example from [this](https://stackoverflow.com/questions/48123049/create-day-index-based-on-water-year))

snotel_327_clean <- snotel_327_clean %>% 
  group_by(waterYear)%>% 
  mutate(waterDay = (as.integer(difftime(Date, ymd(paste0(waterYear - 1 ,'-09-30')), units = "days"))))
# Check for outliers

ggplot(snotel_327_clean, aes(x = Date, y = temperature_mean)) +
  geom_point() + #lwd = 2) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('Daily temperature (°C)') + 
  xlab('Date')

snotel_327_clean <- snotel_327_clean %>% 
  mutate(temp_diff = abs(temperature_min - temperature_max)) %>% 
  filter(temperature_min > -40)
ggplot(snotel_327_clean, aes(x = Date, y = temp_diff)) + 
  geom_point() + #lwd = 2) +
  theme_few() +
  #geom_smooth(method = "lm", se=FALSE) +
  ylab('Daily temperature varience (°C)') + 
  xlab('Date')

Per Steven’s advice: :If there are more than 15 missing days, then…remove that year”

# filtering for temperature anomalies
snotel_327_cull_count <- snotel_327_clean %>% 
  filter(temperature_min < -40) %>% 
  count(waterYear)

snotel_327_cull_count
## # A tibble: 0 x 2
## # Groups:   waterYear [0]
## # ... with 2 variables: waterYear <dbl>, n <int>
# filtering for too few observations in a year
snotel_327_cull_count_days <- snotel_327_clean %>% 
  group_by(waterYear) %>% 
  count(waterYear) %>% 
  filter(n < 350)

snotel_327_cull_count_days
## # A tibble: 3 x 2
## # Groups:   waterYear [3]
##   waterYear     n
##       <dbl> <int>
## 1      1983    52
## 2      1994   337
## 3      2003   346

1983, 1994, 2003 need to be culled.

snotel_327_clean_culled <- snotel_327_clean %>% 
  filter(waterYear != "1983" & waterYear != "1994" & waterYear != "2003") #%>% 
  #filter(temperature_mean > -49)

Beartown (327) NOT ADJUSTED.

2005-04-18 installed ext range sensor. Original

snotel_327_adjusted <- snotel_327_clean_culled %>%
  mutate(temp_ad = if_else(Date < "2005-04-18", ((5.3*10^(-7))*(temperature_mean^(4))+(3.72*10^(-5))*(temperature_mean^(3))-(2.16*10^(-3))*(temperature_mean^(2))-(7.32*10^(-2))*(temperature_mean)+1.37)+temperature_mean, temperature_mean))

Non-corrected

327 Detrended

#using the clean culled df:

#average water year temperature

yearly_wy_aver_327 <- snotel_327_adjusted %>% 
  group_by(waterYear) %>% 
  mutate(aver_ann_temp = mean(temperature_mean))

#Average temperature by day for all water years:

daily_wy_aver_327 <- yearly_wy_aver_327 %>% 
  group_by(daymonth) %>% 
  mutate(aver_day_temp = mean(aver_ann_temp))

#average mean temperature by day for the period of record:

daily_wy_aver_327 <- daily_wy_aver_327 %>% 
  group_by(daymonth) %>% 
  mutate(all_ave_temp = mean(daily_wy_aver_327$aver_day_temp))

# try to show all years as means. 
daily_wy_aver2_327 <-daily_wy_aver_327 %>% 
  group_by(waterDay) %>%
  mutate(date_temp = mean(temperature_mean))
  

daily_wy_aver2_327$date_temp <- signif(daily_wy_aver2_327$date_temp,3) #reduce the sig figs


ggplot(daily_wy_aver2_327, aes(x = waterDay, y = date_temp))+
  geom_line(size= 0.7) +
  theme_few() +
  ylab('Average Daily temperature (°C)') + 
  xlab('Day of water year')

327 SD

standard_dev_327 <- daily_wy_aver_327 %>% 
  group_by(waterYear) %>% 
  mutate(residual = (all_ave_temp-aver_ann_temp)+temperature_mean-aver_day_temp) %>% 
  mutate(deviation = abs(residual-lag(residual)))

standard_dev_all_327 <- standard_dev_327 %>% 
  group_by(waterYear) %>% 
  mutate(nmbr = n())

standard_dev_all_327 <- standard_dev_all_327 %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)

standard_dev_all_327 %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1984 8.215357
1985 8.122497
1986 7.129599
1987 7.619777
1988 8.257318
1989 8.044976
1990 7.675963
1991 7.684970
1992 7.079517
1993 7.642300
1995 7.304999
1996 7.681058
1997 7.711950
1998 8.105700
1999 6.825322
2000 7.526413
2001 7.912097
2002 8.099855
2004 7.622635
2005 7.225545
2006 7.107924
2007 7.426444
2008 7.802192
2009 6.893765
2010 7.820347
2011 7.632307
2012 7.466342
2013 8.000100
2014 7.260505
2015 6.671562
2016 7.474460
2017 7.072348
2018 6.933787
2019 7.658054
2020 7.769482
2021 7.841403
2022 7.318492
ggplot(standard_dev_all_327, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Non-corrected standard deviation of SNOTEL 327 average temperatures for water years 2005-2021

MK & SS for 327 (non-corrected)

sd_mk_327 <- mk.test(standard_dev_all_327$sd_2)
print(sd_mk_327)
## 
##  Mann-Kendall trend test
## 
## data:  standard_dev_all_327$sd_2
## z = -1.818, n = 37, p-value = 0.06907
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##            S         varS          tau 
## -140.0000000 5846.0000000   -0.2102102
sd_sens_327 <- sens.slope(standard_dev_all_327$sd_2)
print(sd_sens_327)
## 
##  Sen's slope
## 
## data:  standard_dev_all_327$sd_2
## z = -1.818, n = 37, p-value = 0.06907
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.025461316  0.001275883
## sample estimates:
## Sen's slope 
## -0.01223021

Summer and Winter SD NOT-CORRECTED

Summer

summer_standard_dev_all_327 <- standard_dev_327 %>%
  filter(waterDay >= 244 & waterDay <= 335) %>%
  group_by(waterYear) %>% 
  mutate(nmbr = n())

summer_standard_dev_all_327 <- summer_standard_dev_all_327 %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)

summer_standard_dev_all_327 %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1984 2.662470
1985 2.202079
1986 2.315446
1987 2.221928
1988 2.666407
1989 2.908971
1990 2.435507
1991 2.288870
1992 2.736828
1993 3.073040
1995 3.177087
1996 2.093670
1997 2.176252
1998 3.039807
1999 2.583979
2000 1.611760
2001 2.304035
2002 2.156006
2004 2.225919
2005 2.858557
2006 1.830347
2007 2.362229
2008 2.159473
2009 2.619961
2010 2.177014
2011 1.814920
2012 1.545735
2013 1.735480
2014 1.867382
2015 2.209308
2016 2.440044
2017 1.787620
2018 1.602691
2019 2.400103
2020 2.288616
2021 2.153505
2022 2.028381
ggplot(summer_standard_dev_all_327, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Non-corrected standard deviation of SNOTEL 327 average summer temperatures for water years 2005-2021

summer MK & SS for 327 (non-corrected)

summer_sd_mk_327 <- mk.test(summer_standard_dev_all_327$sd_2)
print(summer_sd_mk_327)
## 
##  Mann-Kendall trend test
## 
## data:  summer_standard_dev_all_327$sd_2
## z = -2.7858, n = 37, p-value = 0.00534
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##            S         varS          tau 
## -214.0000000 5846.0000000   -0.3213213
summer_sd_sens_327 <- sens.slope(summer_standard_dev_all_327$sd_2)
print(summer_sd_sens_327)
## 
##  Sen's slope
## 
## data:  summer_standard_dev_all_327$sd_2
## z = -2.7858, n = 37, p-value = 0.00534
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.030197599 -0.004550044
## sample estimates:
## Sen's slope 
## -0.01753962

Winter

winter_standard_dev_all_327 <- standard_dev_327 %>%
  filter(waterDay >= 32 & waterDay <= 182) %>%
  group_by(waterYear) %>% 
  mutate(nmbr = n())

winter_standard_dev_all_327 <- winter_standard_dev_all_327 %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)

winter_standard_dev_all_327 %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1984 4.948620
1985 4.804176
1986 4.485164
1987 4.341123
1988 4.957619
1989 5.497259
1990 5.027247
1991 4.699816
1992 3.461224
1993 3.676274
1995 4.234140
1996 4.899380
1997 4.966943
1998 4.384582
1999 4.129867
2000 4.938855
2001 3.977088
2002 4.803227
2004 5.176728
2005 3.988333
2006 4.530121
2007 5.073336
2008 5.395287
2009 4.498157
2010 4.341478
2011 5.174805
2012 4.236838
2013 5.575214
2014 4.008632
2015 4.510259
2016 4.763128
2017 4.971458
2018 4.254628
2019 4.011225
2020 4.438512
2021 4.336327
2022 4.613189
ggplot(winter_standard_dev_all_327, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Non-corrected standard deviation of SNOTEL 327 average winter temperatures for water years 2005-2021

winter MK & SS for 327 (non-corrected)

winter_sd_mk_327 <- mk.test(winter_standard_dev_all_327$sd_2)
print(winter_sd_mk_327)
## 
##  Mann-Kendall trend test
## 
## data:  winter_standard_dev_all_327$sd_2
## z = -0.45776, n = 37, p-value = 0.6471
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##             S          varS           tau 
##  -36.00000000 5846.00000000   -0.05405405
winter_sd_sens_327 <- sens.slope(winter_standard_dev_all_327$sd_2)
print(winter_sd_sens_327)
## 
##  Sen's slope
## 
## data:  winter_standard_dev_all_327$sd_2
## z = -0.45776, n = 37, p-value = 0.6471
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.02107872  0.01135756
## sample estimates:
##  Sen's slope 
## -0.004978217

Spring and Fall SD NOT-CORRECTED

Spring

spring_standard_dev_all_327 <- standard_dev_327 %>%
  filter(waterDay >= 183 & waterDay <= 243) %>%
  group_by(waterYear) %>% 
  mutate(nmbr = n())

spring_standard_dev_all_327 <- spring_standard_dev_all_327 %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)

spring_standard_dev_all_327 %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1984 6.240204
1985 3.253702
1986 4.227948
1987 3.658952
1988 4.426143
1989 4.264808
1990 2.954547
1991 4.633125
1992 3.059636
1993 4.308754
1995 3.823285
1996 5.157898
1997 5.185561
1998 4.942407
1999 4.942243
2000 4.586663
2001 4.532810
2002 3.513378
2004 3.791223
2005 4.363633
2006 3.645641
2007 3.672793
2008 4.362134
2009 4.706274
2010 4.659535
2011 4.159449
2012 3.823576
2013 4.283522
2014 4.682122
2015 2.851996
2016 3.494926
2017 3.982653
2018 4.167826
2019 3.322685
2020 4.260492
2021 3.590339
2022 4.568192
ggplot(spring_standard_dev_all_327, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Non-corrected standard deviation of SNOTEL 327 average spring temperatures for water years 2005-2021

spring MK & SS for 327 (non-corrected)

spring_sd_mk_327 <- mk.test(spring_standard_dev_all_327$sd_2)
print(spring_sd_mk_327)
## 
##  Mann-Kendall trend test
## 
## data:  spring_standard_dev_all_327$sd_2
## z = -0.9286, n = 37, p-value = 0.3531
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##            S         varS          tau 
##  -72.0000000 5846.0000000   -0.1081081
spring_sd_sens_327 <- sens.slope(spring_standard_dev_all_327$sd_2)
print(spring_sd_sens_327)
## 
##  Sen's slope
## 
## data:  spring_standard_dev_all_327$sd_2
## z = -0.9286, n = 37, p-value = 0.3531
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.03403070  0.01203288
## sample estimates:
## Sen's slope 
## -0.01020605

Fall

Fall is split each water year in the middle of the season. This analysis splits the fall season between the preceding water year and the subsequent water year.

fall_standard_dev_all_327 <- standard_dev_327 %>%
  filter(waterDay >= 336 | waterDay <= 31) %>% 
  group_by(waterYear) %>% 
  mutate(nmbr = n())

fall_standard_dev_all_327 <- fall_standard_dev_all_327 %>% 
  #group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)

fall_standard_dev_all_327 %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1984 3.343260
1985 5.234374
1986 3.214065
1987 3.519388
1988 3.446353
1989 5.489907
1990 4.965001
1991 3.385921
1992 4.774508
1993 3.327340
1995 4.529415
1996 3.989789
1997 5.691400
1998 5.266278
1999 3.920075
2000 3.573732
2001 4.451618
2002 3.237858
2004 3.488810
2005 4.211050
2006 3.148012
2007 4.359081
2008 3.556339
2009 3.558493
2010 5.677017
2011 3.804704
2012 4.132184
2013 3.912454
2014 5.221167
2015 2.929296
2016 3.392160
2017 3.098675
2018 3.255937
2019 4.792820
2020 5.733284
2021 3.930113
2022 4.823102
ggplot(fall_standard_dev_all_327, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Non-corrected standard deviation of SNOTEL 327 average fall temperatures for water years 2005-2021. Note that the season is split by the water year.

fall MK & SS for 327 (non-corrected)

fall_sd_mk_327 <- mk.test(fall_standard_dev_all_327$sd_2)
print(fall_sd_mk_327)
## 
##  Mann-Kendall trend test
## 
## data:  fall_standard_dev_all_327$sd_2
## z = 0.013079, n = 37, p-value = 0.9896
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##            S         varS          tau 
## 2.000000e+00 5.846000e+03 3.003003e-03
fall_sd_sens_327 <- sens.slope(fall_standard_dev_all_327$sd_2)
print(fall_sd_sens_327)
## 
##  Sen's slope
## 
## data:  fall_standard_dev_all_327$sd_2
## z = 0.013079, n = 37, p-value = 0.9896
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.02830741  0.02632668
## sample estimates:
##  Sen's slope 
## 0.0003746267

Cascade #2 387

Morrisey 6/18/2004

snotel_387 <- SNOTEL_san_juan_Area %>% 
  filter(site_id == "387")
#str(snotel_387) # check the date, usually a character.  

snotel_387$Date <- as.Date(snotel_387$date) #change date from character to date format, capitalize to work with Water year functon from NWIS.

#THIS WILL CHANGE FOR EACH STATION
snotel_387_clean <- snotel_387 %>% # filter for the timeframe
  filter(Date >= "1979-10-01" & Date <= "2022-09-30") %>%
  #filter(temperature_mean >= -30 & temperature_mean <= 20) %>% # removing outliers   
  addWaterYear() %>% 
  mutate(daymonth = format(as.Date(Date), "%d-%m")) %>% 
  na.omit()

#adding water day using difftime (SUPER COOL. example from [this](https://stackoverflow.com/questions/48123049/create-day-index-based-on-water-year))

snotel_387_clean <- snotel_387_clean %>% 
  group_by(waterYear)%>% 
  mutate(waterDay = (as.integer(difftime(Date, ymd(paste0(waterYear - 1 ,'-09-30')), units = "days"))))
# Check for outliers

ggplot(snotel_387_clean, aes(x = Date, y = temperature_mean)) +
  geom_point() + #lwd = 2) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('Daily temperature (°C)') + 
  xlab('Date')

snotel_387_clean <- snotel_387_clean %>% 
  mutate(temp_diff = abs(temperature_min - temperature_max)) %>% 
  filter(temperature_min > -40) %>% 
  filter(temperature_mean > -40)
ggplot(snotel_387_clean, aes(x = Date, y = temp_diff)) + 
  geom_point() + #lwd = 2) +
  theme_few() +
  #geom_smooth(method = "lm", se=FALSE) +
  ylab('Daily temperature varience (°C)') + 
  xlab('Date')

temp_387_xts <- xts(snotel_387_clean$temperature_mean, order.by = snotel_387_clean$Date)

#dygraph(temp_387_xts) %>%
#  dyAxis("y", label = "Daily mean temperature (°C)") 

Per Steven’s advice: :If there are more than 15 missing days, then…remove that year”

# filtering for temperature anomalies
snotel_387_cull_count <- snotel_387_clean %>% 
  filter(temperature_min > -40) %>% 
  count(waterYear)

snotel_387_cull_count
## # A tibble: 0 x 2
## # Groups:   waterYear [0]
## # ... with 2 variables: waterYear <dbl>, n <int>
# filtering for too few observations in a year
snotel_387_cull_count_days <- snotel_387_clean %>% 
  group_by(waterYear) %>% 
  count(waterYear) %>% 
  filter(n < 350)

snotel_387_cull_count_days
## # A tibble: 0 x 2
## # Groups:   waterYear [0]
## # ... with 2 variables: waterYear <dbl>, n <int>

1993, 1994, 2018, 2022 need to be culled.

snotel_387_clean_culled <- snotel_387_clean %>% 
  filter(waterYear != "1993" & waterYear != "1994" & waterYear != "2018" & waterYear != "2022") #%>% 
  #filter(temperature_mean > -49)

Cascade #2 (387) NOT ADJUSTED.

Morrisey 6/18/2004

snotel_387_adjusted <- snotel_387_clean_culled %>%
  mutate(temp_ad = if_else(Date < "2004-06-18", ((5.3*10^(-7))*(temperature_mean^(4))+(3.72*10^(-5))*(temperature_mean^(3))-(2.16*10^(-3))*(temperature_mean^(2))-(7.32*10^(-2))*(temperature_mean)+1.37)+temperature_mean, temperature_mean))

Non-corrected

387 Detrended

#using the clean culled df:

#average water year temperature

yearly_wy_aver_387 <- snotel_387_adjusted %>% 
  group_by(waterYear) %>% 
  mutate(aver_ann_temp = mean(temperature_mean))

#Average temperature by day for all water years:

daily_wy_aver_387 <- yearly_wy_aver_387 %>% 
  group_by(daymonth) %>% 
  mutate(aver_day_temp = mean(aver_ann_temp))

#average mean temperature by day for the period of record:

daily_wy_aver_387 <- daily_wy_aver_387 %>% 
  group_by(daymonth) %>% 
  mutate(all_ave_temp = mean(daily_wy_aver_387$aver_day_temp))

# try to show all years as means. 
daily_wy_aver2_387 <-daily_wy_aver_387 %>% 
  group_by(waterDay) %>%
  mutate(date_temp = mean(temperature_mean))
  

daily_wy_aver2_387$date_temp <- signif(daily_wy_aver2_387$date_temp,3) #reduce the sig figs


ggplot(daily_wy_aver2_387, aes(x = waterDay, y = date_temp))+
  geom_line(size= 0.7) +
  theme_few() +
  ylab('Average Daily temperature (°C)') + 
  xlab('Day of water year')

387 SD

standard_dev_387 <- daily_wy_aver_387 %>% 
  group_by(waterYear) %>% 
  mutate(residual = (all_ave_temp-aver_ann_temp)+temperature_mean-aver_day_temp) %>% 
  mutate(deviation = abs(residual-lag(residual)))

standard_dev_all_387 <- standard_dev_387 %>% 
  group_by(waterYear) %>% 
  mutate(nmbr = n())

standard_dev_all_387 <- standard_dev_all_387 %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)

standard_dev_all_387 %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
ggplot(standard_dev_all_387, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Non-corrected standard deviation of SNOTEL 387 average temperatures for water years 2005-2021

MK & SS for 387 (non-corrected)

(omitted. knitting errors.)

# Thus is giving an error, omitting it as it does not matter due to the correction. 
sd_mk_387 <- mk.test(standard_dev_all_387$sd_2)
print(sd_mk_387)

sd_sens_387 <- sens.slope(standard_dev_all_387$sd_2)
print(sd_sens_387)

Corrected

387 Detrended (corrected)

#using the clean culled df:
#average water year temperature
yearly_wy_aver_387_ad <- snotel_387_adjusted %>% 
  group_by(waterYear) %>% 
  mutate(aver_ann_temp_ad = mean(temp_ad))
#Average temperature by day for all water years:
daily_wy_aver_387_ad <- yearly_wy_aver_387_ad %>% 
  group_by(daymonth) %>% 
  mutate(aver_day_temp_ad = mean(aver_ann_temp_ad))
#average mean temperature by day for the period of record:
daily_wy_aver_387_ad <- daily_wy_aver_387_ad %>% 
  group_by(daymonth) %>% 
  mutate(all_ave_temp_ad = mean(daily_wy_aver_387_ad$aver_day_temp_ad))
# try to show all years as means. 
daily_wy_aver2_387_ad <-daily_wy_aver_387_ad %>% 
  group_by(waterDay) %>%
  mutate(date_temp_ad = mean(temp_ad))
  
daily_wy_aver2_387_ad$date_temp_ad <- signif(daily_wy_aver2_387_ad$date_temp_ad,3) #reduce the sig figs
ggplot(daily_wy_aver2_387_ad, aes(x = waterDay, y = date_temp_ad))+
  geom_line(size= 0.7) +
  theme_few() +
  ylab('Average Daily temperature (°C)') + 
  xlab('Day of water year')

387 SS (corrected)

standard_dev_387_ad <- daily_wy_aver_387_ad %>% 
  group_by(waterYear) %>% 
  #filter(waterYear >= 1987 & waterYear <= 2021) %>% 
  mutate(residual = (all_ave_temp_ad-aver_ann_temp_ad)+temp_ad-aver_day_temp_ad) %>% 
  mutate(deviation = abs(residual-lag(residual)))
standard_dev_all_387_ad <- standard_dev_387_ad %>% 
  group_by(waterYear) %>% 
  mutate(nmbr = n())
standard_dev_all_387_ad <- standard_dev_all_387_ad %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)
standard_dev_all_387_ad %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
ggplot(standard_dev_all_387_ad, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Morrisey-corrected standard deviation of SNOTEL 387 average temperatures for water years 1986-2021

MK & SS 387 (corrected)

(Getting errors knitting. Including results.)

sd_mk_387_ad <- mk.test(standard_dev_all_387_ad$sd_2)
print(sd_mk_387_ad)

sd_sens_387_ad <- sens.slope(standard_dev_all_387_ad$sd_2)
print(sd_sens_387_ad)
Mann-Kendall trend test

data: standard_dev_all_387_ad$sd_2 z = 1.0076, n = 28, p-value = 0.3137 alternative hypothesis: true S is not equal to 0 sample estimates: S varS tau 52.0000000 2562.0000000 0.1375661

sd_sens_387_ad <- sens.slope(standard_dev_all_387_ad$sd_2) print(sd_sens_387_ad)

Sen's slope

data: standard_dev_all_387_ad$sd_2 z = 1.0076, n = 28, p-value = 0.3137 alternative hypothesis: true z is not equal to 0 95 percent confidence interval: -0.01132335 0.02876884 sample estimates: Sen’s slope 0.01333464

Summer and Winter SD NOT-CORRECTED

Summer

summer_standard_dev_all_387 <- standard_dev_387 %>%
  filter(waterDay >= 244 & waterDay <= 335) %>%
  group_by(waterYear) %>% 
  mutate(nmbr = n())

summer_standard_dev_all_387 <- summer_standard_dev_all_387 %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)

summer_standard_dev_all_387 %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
ggplot(summer_standard_dev_all_387, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Non-corrected standard deviation of SNOTEL 387 average summer temperatures for water years 2005-2021

summer MK & SS for 387 (non-corrected)

(Errors~!)

summer_sd_mk_387 <- mk.test(summer_standard_dev_all_387$sd_2)
print(summer_sd_mk_387)

summer_sd_sens_387 <- sens.slope(summer_standard_dev_all_387$sd_2)
print(summer_sd_sens_387)
Mann-Kendall trend test

data: summer_standard_dev_all_387$sd_2 z = -3.1018, n = 28, p-value = 0.001924 alternative hypothesis: true S is not equal to 0 sample estimates: S varS tau -158.0000000 2562.0000000 -0.4179894

summer_sd_sens_387 <- sens.slope(summer_standard_dev_all_387$sd_2) print(summer_sd_sens_387)

Sen's slope

data: summer_standard_dev_all_387$sd_2 z = -3.1018, n = 28, p-value = 0.001924 alternative hypothesis: true z is not equal to 0 95 percent confidence interval: -0.04957977 -0.01397734 sample estimates: Sen’s slope -0.03381096

Winter

winter_standard_dev_all_387 <- standard_dev_387 %>%
  filter(waterDay >= 32 & waterDay <= 182) %>%
  group_by(waterYear) %>% 
  mutate(nmbr = n())

winter_standard_dev_all_387 <- winter_standard_dev_all_387 %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)

winter_standard_dev_all_387 %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
ggplot(winter_standard_dev_all_387, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Non-corrected standard deviation of SNOTEL 387 average winter temperatures for water years 2005-2021

winter MK & SS for 387 (non-corrected)

winter_sd_mk_387 <- mk.test(winter_standard_dev_all_387$sd_2)
print(winter_sd_mk_387)

winter_sd_sens_387 <- sens.slope(winter_standard_dev_all_387$sd_2)
print(winter_sd_sens_387)
Mann-Kendall trend test

data: winter_standard_dev_all_387$sd_2 z = -0.29635, n = 28, p-value = 0.767 alternative hypothesis: true S is not equal to 0 sample estimates: S varS tau -16.00000000 2562.00000000 -0.04232804

winter_sd_sens_387 <- sens.slope(winter_standard_dev_all_387$sd_2) print(winter_sd_sens_387)

Sen's slope

data: winter_standard_dev_all_387$sd_2 z = -0.29635, n = 28, p-value = 0.767 alternative hypothesis: true z is not equal to 0 95 percent confidence interval: -0.03388152 0.02134071 sample estimates: Sen’s slope -0.004115886

Summer and Winter SD CORRECTED

Summer

summer_standard_dev_all_387_ad <- standard_dev_387_ad %>% 
  filter(waterDay >= 244 & waterDay <= 335) %>%
  group_by(waterYear) %>% 
  mutate(nmbr = n())
summer_standard_dev_all_387_ad <- summer_standard_dev_all_387_ad %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)
summer_standard_dev_all_387_ad %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
ggplot(summer_standard_dev_all_387_ad, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Morrisey-corrected standard deviation of SNOTEL 387 average summer temperatures for water years 1986-2021

summer MK & SS 387 (corrected)

summer_sd_mk_387_ad <- mk.test(summer_standard_dev_all_387_ad$sd_2)
print(summer_sd_mk_387_ad)

summer_sd_sens_387_ad <- sens.slope(summer_standard_dev_all_387_ad$sd_2)
print(summer_sd_sens_387_ad)
Mann-Kendall trend test

data: summer_standard_dev_all_387_ad$sd_2 z = -2.1139, n = 28, p-value = 0.03452 alternative hypothesis: true S is not equal to 0 sample estimates: S varS tau -108.0000000 2562.0000000 -0.2857143

summer_sd_sens_387_ad <- sens.slope(summer_standard_dev_all_387_ad$sd_2) print(summer_sd_sens_387_ad)

Sen's slope

data: summer_standard_dev_all_387_ad$sd_2 z = -2.1139, n = 28, p-value = 0.03452 alternative hypothesis: true z is not equal to 0 95 percent confidence interval: -0.03503134 -0.00096542 sample estimates: Sen’s slope -0.01659336

Winter

winter_standard_dev_all_387_ad <- standard_dev_387_ad %>% 
  filter(waterDay >= 32 & waterDay <= 182) %>%
  group_by(waterYear) %>% 
  mutate(nmbr = n())
winter_standard_dev_all_387_ad <- winter_standard_dev_all_387_ad %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)
winter_standard_dev_all_387_ad %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
ggplot(winter_standard_dev_all_387_ad, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Morrisey-corrected standard deviation of SNOTEL 387 average winter temperatures for water years 1986-2021

winter MK & SS 387 (corrected)

winter_sd_mk_387_ad <- mk.test(winter_standard_dev_all_387_ad$sd_2)
print(winter_sd_mk_387_ad)

winter_sd_sens_387_ad <- sens.slope(winter_standard_dev_all_387_ad$sd_2)
print(winter_sd_sens_387_ad)
Mann-Kendall trend test

data: winter_standard_dev_all_387_ad$sd_2 z = 0.53343, n = 28, p-value = 0.5937 alternative hypothesis: true S is not equal to 0 sample estimates: S varS tau 2.800000e+01 2.562000e+03 7.407407e-02

winter_sd_sens_387_ad <- sens.slope(winter_standard_dev_all_387_ad$sd_2) print(winter_sd_sens_387_ad)

Sen's slope

data: winter_standard_dev_all_387_ad$sd_2 z = 0.53343, n = 28, p-value = 0.5937 alternative hypothesis: true z is not equal to 0 95 percent confidence interval: -0.01913536 0.03018631 sample estimates: Sen’s slope 0.007065364

Spring and Fall SD NOT-CORRECTED

Spring

spring_standard_dev_all_387 <- standard_dev_387 %>%
  filter(waterDay >= 183 & waterDay <= 243) %>%
  group_by(waterYear) %>% 
  mutate(nmbr = n())

spring_standard_dev_all_387 <- spring_standard_dev_all_387 %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)

spring_standard_dev_all_387 %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
ggplot(spring_standard_dev_all_387, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Non-corrected standard deviation of SNOTEL 387 average spring temperatures for water years 2005-2021

spring MK & SS for 387 (non-corrected)

spring_sd_mk_387 <- mk.test(spring_standard_dev_all_387$sd_2)
print(spring_sd_mk_387)

spring_sd_sens_387 <- sens.slope(spring_standard_dev_all_387$sd_2)
print(spring_sd_sens_387)
Mann-Kendall trend test

data: spring_standard_dev_all_387$sd_2 z = -2.7857, n = 28, p-value = 0.005342 alternative hypothesis: true S is not equal to 0 sample estimates: S varS tau -142.0000000 2562.0000000 -0.3756614

spring_sd_sens_387 <- sens.slope(spring_standard_dev_all_387$sd_2) print(spring_sd_sens_387)

Sen's slope

data: spring_standard_dev_all_387$sd_2 z = -2.7857, n = 28, p-value = 0.005342 alternative hypothesis: true z is not equal to 0 95 percent confidence interval: -0.08861795 -0.01960648 sample estimates: Sen’s slope -0.05890488

Fall

Fall is split each water year in the middle of the season. This analysis splits the fall season between the preceding water year and the subsequent water year.

fall_standard_dev_all_387 <- standard_dev_387 %>%
  filter(waterDay >= 336 | waterDay <= 31) %>% 
  group_by(waterYear) %>% 
  mutate(nmbr = n())

fall_standard_dev_all_387 <- fall_standard_dev_all_387 %>% 
  #group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)

fall_standard_dev_all_387 %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
ggplot(fall_standard_dev_all_387, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Non-corrected standard deviation of SNOTEL 387 average fall temperatures for water years 2005-2021. Note that the season is split by the water year.

fall MK & SS for 387 (non-corrected)

fall_sd_mk_387 <- mk.test(fall_standard_dev_all_387$sd_2)
print(fall_sd_mk_387)

fall_sd_sens_387 <- sens.slope(fall_standard_dev_all_387$sd_2)
print(fall_sd_sens_387)

Mann-Kendall trend test

data: fall_standard_dev_all_387$sd_2 z = -0.88904, n = 28, p-value = 0.374 alternative hypothesis: true S is not equal to 0 sample estimates: S varS tau -46.0000000 2562.0000000 -0.1216931

fall_sd_sens_387 <- sens.slope(fall_standard_dev_all_387$sd_2) print(fall_sd_sens_387)

Sen's slope

data: fall_standard_dev_all_387$sd_2 z = -0.88904, n = 28, p-value = 0.374 alternative hypothesis: true z is not equal to 0 95 percent confidence interval: -0.05742459 0.01997105 sample estimates: Sen’s slope -0.01857758

Spring and Fall SD CORRECTED

Spring

spring_standard_dev_all_387_ad <- standard_dev_387_ad %>% 
  filter(waterDay >= 183 & waterDay <= 243) %>%
  group_by(waterYear) %>% 
  mutate(nmbr = n())
spring_standard_dev_all_387_ad <- spring_standard_dev_all_387_ad %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)
spring_standard_dev_all_387_ad %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
ggplot(spring_standard_dev_all_387_ad, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Morrisey-corrected standard deviation of SNOTEL 387 average spring temperatures for water years 1986-2021

spring MK & SS 387 (corrected)

spring_sd_mk_387_ad <- mk.test(spring_standard_dev_all_387_ad$sd_2)
print(spring_sd_mk_387_ad)

spring_sd_sens_387_ad <- sens.slope(spring_standard_dev_all_387_ad$sd_2)
print(spring_sd_sens_387_ad)
Mann-Kendall trend test

data: spring_standard_dev_all_387_ad$sd_2 z = -2.1139, n = 28, p-value = 0.03452 alternative hypothesis: true S is not equal to 0 sample estimates: S varS tau -108.0000000 2562.0000000 -0.2857143

spring_sd_sens_387_ad <- sens.slope(spring_standard_dev_all_387_ad$sd_2) print(spring_sd_sens_387_ad)

Sen's slope

data: spring_standard_dev_all_387_ad$sd_2 z = -2.1139, n = 28, p-value = 0.03452 alternative hypothesis: true z is not equal to 0 95 percent confidence interval: -0.065018532 -0.001597276 sample estimates: Sen’s slope -0.03620446

Fall

fall_standard_dev_all_387_ad <- standard_dev_387_ad %>% 
  filter(waterDay >= 336 | waterDay <= 31) %>%
  group_by(waterYear) %>% 
  mutate(nmbr = n())
fall_standard_dev_all_387_ad <- fall_standard_dev_all_387_ad %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)
fall_standard_dev_all_387_ad %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
ggplot(fall_standard_dev_all_387_ad, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Morrisey-corrected standard deviation of SNOTEL 387 average fall temperatures for water years 1986-2021. Note that the fall season is split by the water year.

fall MK & SS 387 (corrected)

fall_sd_mk_387_ad <- mk.test(fall_standard_dev_all_387_ad$sd_2)
print(fall_sd_mk_387_ad)

fall_sd_sens_387_ad <- sens.slope(fall_standard_dev_all_387_ad$sd_2)
print(fall_sd_sens_387_ad)

Mann-Kendall trend test

data: fall_standard_dev_all_387_ad$sd_2 z = 0.019757, n = 28, p-value = 0.9842 alternative hypothesis: true S is not equal to 0 sample estimates: S varS tau 2.000000e+00 2.562000e+03 5.291005e-03

fall_sd_sens_387_ad <- sens.slope(fall_standard_dev_all_387_ad$sd_2) print(fall_sd_sens_387_ad)

Sen's slope

data: fall_standard_dev_all_387_ad$sd_2 z = 0.019757, n = 28, p-value = 0.9842 alternative hypothesis: true z is not equal to 0 95 percent confidence interval: -0.03187009 0.04007064 sample estimates: Sen’s slope 0.002865928

Cumbres Trestle 431

Oyler -> Morrisey 6/8/2005

snotel_431 <- SNOTEL_san_juan_Area %>% 
  filter(site_id == "431")
#str(snotel_431) # check the date, usually a character.  

snotel_431$Date <- as.Date(snotel_431$date) #change date from character to date format, capitalize to work with Water year functon from NWIS.

#THIS WILL CHANGE FOR EACH STATION
snotel_431_clean <- snotel_431 %>% # filter for the timeframe
  filter(Date >= "1979-10-01" & Date <= "2022-09-30") %>%
  #filter(temperature_mean >= -30 & temperature_mean <= 20) %>% # removing outliers   
  addWaterYear() %>% 
  mutate(daymonth = format(as.Date(Date), "%d-%m")) %>% 
  na.omit()

#adding water day using difftime (SUPER COOL. example from [this](https://stackoverflow.com/questions/48123049/create-day-index-based-on-water-year))

snotel_431_clean <- snotel_431_clean %>% 
  group_by(waterYear)%>% 
  mutate(waterDay = (as.integer(difftime(Date, ymd(paste0(waterYear - 1 ,'-09-30')), units = "days"))))
# Check for outliers

ggplot(snotel_431_clean, aes(x = Date, y = temperature_mean)) +
  geom_point() + #lwd = 2) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('Daily temperature (°C)') + 
  xlab('Date')

snotel_431_clean <- snotel_431_clean %>% 
  mutate(temp_diff = abs(temperature_min - temperature_max)) %>% 
  filter(temperature_min > -40) %>% 
  filter(temperature_min < 25)
ggplot(snotel_431_clean, aes(x = Date, y = temp_diff)) + 
  geom_point() + #lwd = 2) +
  theme_few() +
  #geom_smooth(method = "lm", se=FALSE) +
  ylab('Daily temperature varience (°C)') + 
  xlab('Date')

Per Steven’s advice: :If there are more than 15 missing days, then…remove that year”

# filtering for temperature anomalies
snotel_431_cull_count <- snotel_431_clean %>% 
  filter(temperature_min > -40) %>% 
  count(waterYear)

snotel_431_cull_count
## # A tibble: 36 x 2
## # Groups:   waterYear [36]
##    waterYear     n
##        <dbl> <int>
##  1      1987     1
##  2      1988   341
##  3      1989   364
##  4      1990   348
##  5      1991   341
##  6      1992   312
##  7      1993   356
##  8      1994   317
##  9      1995   364
## 10      1996   364
## # ... with 26 more rows
# filtering for too few observations in a year
snotel_431_cull_count_days <- snotel_431_clean %>% 
  group_by(waterYear) %>% 
  count(waterYear) %>% 
  filter(n < 350)

snotel_431_cull_count_days
## # A tibble: 7 x 2
## # Groups:   waterYear [7]
##   waterYear     n
##       <dbl> <int>
## 1      1987     1
## 2      1988   341
## 3      1990   348
## 4      1991   341
## 5      1992   312
## 6      1994   317
## 7      2014   288

1987, 1988, 1990, 1991, 1992, 1994, 2014 need to be culled.

snotel_431_clean_culled <- snotel_431_clean %>% 
  filter(waterYear != "1987" & waterYear != "1988" & waterYear != "1990" & waterYear != "1991" & waterYear != "1992" & waterYear != "1994" & waterYear != "2014") #%>% 
  #filter(temperature_mean > -49)
ggplot(snotel_431_clean_culled, aes(x = Date, y = temperature_mean)) + 
  geom_point() + #lwd = 2) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('Daily temperature (°C)') + 
  xlab('Date')

temp_431_xts <- xts(snotel_431_clean_culled$temperature_mean, order.by = snotel_431_clean_culled$Date)

dygraph(temp_431_xts) %>%
  dyAxis("y", label = "Daily mean temperature (°C)") 
snotel_431_clean_culled <- snotel_431_clean_culled %>% 
  filter(temperature_mean < 20)

temp_431_xts <- xts(snotel_431_clean_culled$temperature_mean, order.by = snotel_431_clean_culled$Date)

dygraph(temp_431_xts) %>%
  dyAxis("y", label = "Daily mean temperature (°C)") 

Cumbres Trestle 431

Oyler -> Morrisey 6/8/2005

snotel_431_adjusted <- snotel_431_clean_culled %>%
  mutate(temp_ad = if_else(Date < "2005-06-08", ((5.3*10^(-7))*(temperature_mean^(4))+(3.72*10^(-5))*(temperature_mean^(3))-(2.16*10^(-3))*(temperature_mean^(2))-(7.32*10^(-2))*(temperature_mean)+1.37)+temperature_mean, temperature_mean))

Non-corrected

431 Detrended

#using the clean culled df:

#average water year temperature

yearly_wy_aver_431 <- snotel_431_adjusted %>% 
  group_by(waterYear) %>% 
  mutate(aver_ann_temp = mean(temperature_mean))

#Average temperature by day for all water years:

daily_wy_aver_431 <- yearly_wy_aver_431 %>% 
  group_by(daymonth) %>% 
  mutate(aver_day_temp = mean(aver_ann_temp))

#average mean temperature by day for the period of record:

daily_wy_aver_431 <- daily_wy_aver_431 %>% 
  group_by(daymonth) %>% 
  mutate(all_ave_temp = mean(daily_wy_aver_431$aver_day_temp))

# try to show all years as means. 
daily_wy_aver2_431 <-daily_wy_aver_431 %>% 
  group_by(waterDay) %>%
  mutate(date_temp = mean(temperature_mean))
  

daily_wy_aver2_431$date_temp <- signif(daily_wy_aver2_431$date_temp,3) #reduce the sig figs


ggplot(daily_wy_aver2_431, aes(x = waterDay, y = date_temp))+
  geom_line(size= 0.7) +
  theme_few() +
  ylab('Average Daily temperature (°C)') + 
  xlab('Day of water year')

431 SD

standard_dev_431 <- daily_wy_aver_431 %>% 
  group_by(waterYear) %>% 
  mutate(residual = (all_ave_temp-aver_ann_temp)+temperature_mean-aver_day_temp) %>% 
  mutate(deviation = abs(residual-lag(residual)))

standard_dev_all_431 <- standard_dev_431 %>% 
  group_by(waterYear) %>% 
  mutate(nmbr = n())

standard_dev_all_431 <- standard_dev_all_431 %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)

standard_dev_all_431 %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1989 8.484011
1993 8.101376
1995 7.750446
1996 7.952021
1997 8.217323
1998 8.600343
1999 7.226028
2000 8.164156
2001 8.669911
2002 9.005161
2003 8.459072
2004 8.306872
2005 8.304679
2006 7.417238
2007 7.937180
2008 8.259566
2009 7.296965
2010 8.418225
2011 8.231369
2012 8.081428
2013 8.537331
2015 7.219164
2016 7.791453
2017 7.322790
2018 7.113402
2019 7.880447
2020 8.046531
2021 8.095523
2022 7.621146
ggplot(standard_dev_all_431, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Non-corrected standard deviation of SNOTEL 431 average temperatures for water years 2005-2021

MK & SS for 431 (non-corrected)

sd_mk_431 <- mk.test(standard_dev_all_431$sd_2)
print(sd_mk_431)
## 
##  Mann-Kendall trend test
## 
## data:  standard_dev_all_431$sd_2
## z = -1.9321, n = 29, p-value = 0.05335
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##            S         varS          tau 
## -104.0000000 2842.0000000   -0.2561576
sd_sens_431 <- sens.slope(standard_dev_all_431$sd_2)
print(sd_sens_431)
## 
##  Sen's slope
## 
## data:  standard_dev_all_431$sd_2
## z = -1.9321, n = 29, p-value = 0.05335
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.041299369  0.001003281
## sample estimates:
## Sen's slope 
## -0.01890302

Corrected

431 Detrended (corrected)

#using the clean culled df:
#average water year temperature
yearly_wy_aver_431_ad <- snotel_431_adjusted %>% 
  group_by(waterYear) %>% 
  mutate(aver_ann_temp_ad = mean(temp_ad))
#Average temperature by day for all water years:
daily_wy_aver_431_ad <- yearly_wy_aver_431_ad %>% 
  group_by(daymonth) %>% 
  mutate(aver_day_temp_ad = mean(aver_ann_temp_ad))
#average mean temperature by day for the period of record:
daily_wy_aver_431_ad <- daily_wy_aver_431_ad %>% 
  group_by(daymonth) %>% 
  mutate(all_ave_temp_ad = mean(daily_wy_aver_431_ad$aver_day_temp_ad))
# try to show all years as means. 
daily_wy_aver2_431_ad <-daily_wy_aver_431_ad %>% 
  group_by(waterDay) %>%
  mutate(date_temp_ad = mean(temp_ad))
  
daily_wy_aver2_431_ad$date_temp_ad <- signif(daily_wy_aver2_431_ad$date_temp_ad,3) #reduce the sig figs
ggplot(daily_wy_aver2_431_ad, aes(x = waterDay, y = date_temp_ad))+
  geom_line(size= 0.7) +
  theme_few() +
  ylab('Average Daily temperature (°C)') + 
  xlab('Day of water year')

431 SS (corrected)

standard_dev_431_ad <- daily_wy_aver_431_ad %>% 
  group_by(waterYear) %>% 
  #filter(waterYear >= 1987 & waterYear <= 2021) %>% 
  mutate(residual = (all_ave_temp_ad-aver_ann_temp_ad)+temp_ad-aver_day_temp_ad) %>% 
  mutate(deviation = abs(residual-lag(residual)))
standard_dev_all_431_ad <- standard_dev_431_ad %>% 
  group_by(waterYear) %>% 
  mutate(nmbr = n())
standard_dev_all_431_ad <- standard_dev_all_431_ad %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)
standard_dev_all_431_ad %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1989 7.914872
1993 7.518415
1995 7.173944
1996 7.365597
1997 7.634730
1998 7.970563
1999 6.682639
2000 7.537564
2001 8.039524
2002 8.344015
2003 7.813684
2004 7.737034
2005 7.599212
2006 7.418573
2007 7.938448
2008 8.260644
2009 7.298209
2010 8.419846
2011 8.232506
2012 8.082571
2013 8.538590
2015 7.220737
2016 7.793079
2017 7.324026
2018 7.114853
2019 7.881605
2020 8.047598
2021 8.096826
2022 7.622159
ggplot(standard_dev_all_431_ad, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Morrisey-corrected standard deviation of SNOTEL 431 average temperatures for water years 1986-2021

MK & SS 431 (corrected)

sd_mk_431_ad <- mk.test(standard_dev_all_431_ad$sd_2)
print(sd_mk_431_ad)
## 
##  Mann-Kendall trend test
## 
## data:  standard_dev_all_431_ad$sd_2
## z = 0.99418, n = 29, p-value = 0.3201
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##            S         varS          tau 
##   54.0000000 2842.0000000    0.1330049
sd_sens_431_ad <- sens.slope(standard_dev_all_431_ad$sd_2)
print(sd_sens_431_ad)
## 
##  Sen's slope
## 
## data:  standard_dev_all_431_ad$sd_2
## z = 0.99418, n = 29, p-value = 0.3201
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.01334615  0.03134200
## sample estimates:
## Sen's slope 
##  0.01029449

Summer and Winter SD NOT-CORRECTED

Summer

summer_standard_dev_all_431 <- standard_dev_431 %>%
  filter(waterDay >= 244 & waterDay <= 335) %>%
  group_by(waterYear) %>% 
  mutate(nmbr = n())

summer_standard_dev_all_431 <- summer_standard_dev_all_431 %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)

summer_standard_dev_all_431 %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1989 2.753414
1993 2.753498
1995 2.968036
1996 2.004188
1997 2.331962
1998 2.670393
1999 2.395906
2000 1.868394
2001 2.255163
2002 2.114542
2003 2.976102
2004 2.230182
2005 2.660337
2006 1.780228
2007 2.416832
2008 2.187852
2009 2.461896
2010 2.036498
2011 1.867116
2012 1.665295
2013 1.649738
2015 1.951124
2016 2.508294
2017 1.793169
2018 1.791966
2019 2.345594
2020 2.094093
2021 2.284195
2022 2.148142
ggplot(summer_standard_dev_all_431, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Non-corrected standard deviation of SNOTEL 431 average summer temperatures for water years 2005-2021

summer MK & SS for 431 (non-corrected)

summer_sd_mk_431 <- mk.test(summer_standard_dev_all_431$sd_2)
print(summer_sd_mk_431)
## 
##  Mann-Kendall trend test
## 
## data:  summer_standard_dev_all_431$sd_2
## z = -2.4573, n = 29, p-value = 0.014
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##            S         varS          tau 
## -132.0000000 2842.0000000   -0.3251232
summer_sd_sens_431 <- sens.slope(summer_standard_dev_all_431$sd_2)
print(summer_sd_sens_431)
## 
##  Sen's slope
## 
## data:  summer_standard_dev_all_431$sd_2
## z = -2.4573, n = 29, p-value = 0.014
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.040118705 -0.006476229
## sample estimates:
## Sen's slope 
## -0.02200642

Winter

winter_standard_dev_all_431 <- standard_dev_431 %>%
  filter(waterDay >= 32 & waterDay <= 182) %>%
  group_by(waterYear) %>% 
  mutate(nmbr = n())

winter_standard_dev_all_431 <- winter_standard_dev_all_431 %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)

winter_standard_dev_all_431 %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1989 5.673812
1993 3.905666
1995 4.261318
1996 4.685947
1997 5.018318
1998 4.275724
1999 4.204865
2000 4.747757
2001 4.059343
2002 5.261975
2003 3.868759
2004 5.498182
2005 3.823009
2006 4.518857
2007 5.221438
2008 5.738927
2009 4.351076
2010 4.383378
2011 5.344746
2012 4.195307
2013 5.798016
2015 4.763366
2016 4.785310
2017 4.944345
2018 4.038014
2019 3.978953
2020 4.363272
2021 4.251794
2022 4.600003
ggplot(winter_standard_dev_all_431, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Non-corrected standard deviation of SNOTEL 431 average winter temperatures for water years 2005-2021

winter MK & SS for 431 (non-corrected)

winter_sd_mk_431 <- mk.test(winter_standard_dev_all_431$sd_2)
print(winter_sd_mk_431)
## 
##  Mann-Kendall trend test
## 
## data:  winter_standard_dev_all_431$sd_2
## z = -0.018758, n = 29, p-value = 0.985
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##             S          varS           tau 
## -2.000000e+00  2.842000e+03 -4.926108e-03
winter_sd_sens_431 <- sens.slope(winter_standard_dev_all_431$sd_2)
print(winter_sd_sens_431)
## 
##  Sen's slope
## 
## data:  winter_standard_dev_all_431$sd_2
## z = -0.018758, n = 29, p-value = 0.985
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.03484063  0.02642360
## sample estimates:
##   Sen's slope 
## -0.0005581102

Summer and Winter SD CORRECTED

Summer

summer_standard_dev_all_431_ad <- standard_dev_431_ad %>% 
  filter(waterDay >= 244 & waterDay <= 335) %>%
  group_by(waterYear) %>% 
  mutate(nmbr = n())
summer_standard_dev_all_431_ad <- summer_standard_dev_all_431_ad %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)
summer_standard_dev_all_431_ad %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1989 2.470381
1993 2.476121
1995 2.662238
1996 1.796567
1997 2.096373
1998 2.397172
1999 2.152429
2000 1.671520
2001 2.025994
2002 1.892540
2003 2.663410
2004 2.000228
2005 2.559237
2006 1.782485
2007 2.416990
2008 2.188493
2009 2.460397
2010 2.037137
2011 1.863873
2012 1.668191
2013 1.649971
2015 1.952937
2016 2.511608
2017 1.796713
2018 1.792051
2019 2.342931
2020 2.092982
2021 2.286197
2022 2.146296
ggplot(summer_standard_dev_all_431_ad, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Morrisey-corrected standard deviation of SNOTEL 431 average summer temperatures for water years 1986-2021

summer MK & SS 431 (corrected)

summer_sd_mk_431_ad <- mk.test(summer_standard_dev_all_431_ad$sd_2)
print(summer_sd_mk_431_ad)
## 
##  Mann-Kendall trend test
## 
## data:  summer_standard_dev_all_431_ad$sd_2
## z = -1.2568, n = 29, p-value = 0.2088
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##            S         varS          tau 
##  -68.0000000 2842.0000000   -0.1674877
summer_sd_sens_431_ad <- sens.slope(summer_standard_dev_all_431_ad$sd_2)
print(summer_sd_sens_431_ad)
## 
##  Sen's slope
## 
## data:  summer_standard_dev_all_431_ad$sd_2
## z = -1.2568, n = 29, p-value = 0.2088
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.025484968  0.006205015
## sample estimates:
## Sen's slope 
## -0.01018055

Winter

winter_standard_dev_all_431_ad <- standard_dev_431_ad %>% 
  filter(waterDay >= 32 & waterDay <= 182) %>%
  group_by(waterYear) %>% 
  mutate(nmbr = n())
winter_standard_dev_all_431_ad <- winter_standard_dev_all_431_ad %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)
winter_standard_dev_all_431_ad %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1989 5.465125
1993 3.755367
1995 4.083871
1996 4.496507
1997 4.817101
1998 4.097535
1999 4.014583
2000 4.525336
2001 3.907362
2002 5.029857
2003 3.707729
2004 5.281855
2005 3.684290
2006 4.518705
2007 5.221173
2008 5.738715
2009 4.351342
2010 4.383690
2011 5.344536
2012 4.195071
2013 5.798491
2015 4.763594
2016 4.785655
2017 4.943994
2018 4.038118
2019 3.978630
2020 4.363460
2021 4.251814
2022 4.600094
ggplot(winter_standard_dev_all_431_ad, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Morrisey-corrected standard deviation of SNOTEL 431 average winter temperatures for water years 1986-2021

winter MK & SS 431 (corrected)

winter_sd_mk_431_ad <- mk.test(winter_standard_dev_all_431_ad$sd_2)
print(winter_sd_mk_431_ad)
## 
##  Mann-Kendall trend test
## 
## data:  winter_standard_dev_all_431_ad$sd_2
## z = 0.46895, n = 29, p-value = 0.6391
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##            S         varS          tau 
## 2.600000e+01 2.842000e+03 6.403941e-02
winter_sd_sens_431_ad <- sens.slope(winter_standard_dev_all_431_ad$sd_2)
print(winter_sd_sens_431_ad)
## 
##  Sen's slope
## 
## data:  winter_standard_dev_all_431_ad$sd_2
## z = 0.46895, n = 29, p-value = 0.6391
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.02353986  0.03508924
## sample estimates:
## Sen's slope 
## 0.007052816

Spring and Fall SD NOT-CORRECTED

Spring

spring_standard_dev_all_431 <- standard_dev_431 %>%
  filter(waterDay >= 183 & waterDay <= 243) %>%
  group_by(waterYear) %>% 
  mutate(nmbr = n())

spring_standard_dev_all_431 <- spring_standard_dev_all_431 %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)

spring_standard_dev_all_431 %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1989 3.635249
1993 3.750908
1995 3.668932
1996 5.038684
1997 4.629121
1998 4.897591
1999 4.925389
2000 4.728931
2001 4.520846
2002 3.356016
2003 4.841640
2004 3.786173
2005 4.314206
2006 3.486831
2007 3.445341
2008 4.020057
2009 4.561959
2010 4.347993
2011 4.081706
2012 3.677542
2013 4.104080
2015 2.710644
2016 3.536435
2017 4.041170
2018 3.756903
2019 3.143882
2020 3.696265
2021 3.349286
2022 4.107676
ggplot(spring_standard_dev_all_431, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Non-corrected standard deviation of SNOTEL 431 average spring temperatures for water years 2005-2021

spring MK & SS for 431 (non-corrected)

spring_sd_mk_431 <- mk.test(spring_standard_dev_all_431$sd_2)
print(spring_sd_mk_431)
## 
##  Mann-Kendall trend test
## 
## data:  spring_standard_dev_all_431$sd_2
## z = -2.1572, n = 29, p-value = 0.03099
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##            S         varS          tau 
## -116.0000000 2842.0000000   -0.2857143
spring_sd_sens_431 <- sens.slope(spring_standard_dev_all_431$sd_2)
print(spring_sd_sens_431)
## 
##  Sen's slope
## 
## data:  spring_standard_dev_all_431$sd_2
## z = -2.1572, n = 29, p-value = 0.03099
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.061037207 -0.005596859
## sample estimates:
## Sen's slope 
## -0.03720456

Fall

Fall is split each water year in the middle of the season. This analysis splits the fall season between the preceding water year and the subsequent water year.

fall_standard_dev_all_431 <- standard_dev_431 %>%
  filter(waterDay >= 336 | waterDay <= 31) %>% 
  group_by(waterYear) %>% 
  mutate(nmbr = n())

fall_standard_dev_all_431 <- fall_standard_dev_all_431 %>% 
  #group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)

fall_standard_dev_all_431 %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1989 2.849378
1993 3.116184
1995 4.911526
1996 3.795569
1997 5.995309
1998 5.771561
1999 4.018458
2000 4.300641
2001 4.629887
2002 3.664052
2003 4.371325
2004 3.622571
2005 5.144316
2006 3.023081
2007 4.461661
2008 3.327680
2009 3.369733
2010 5.630619
2011 3.759528
2012 4.339647
2013 4.057390
2015 3.084260
2016 3.372568
2017 3.125867
2018 3.639968
2019 4.629501
2020 5.733073
2021 4.422264
2022 4.765210
ggplot(fall_standard_dev_all_431, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Non-corrected standard deviation of SNOTEL 431 average fall temperatures for water years 2005-2021. Note that the season is split by the water year.

fall MK & SS for 431 (non-corrected)

fall_sd_mk_431 <- mk.test(fall_standard_dev_all_431$sd_2)
print(fall_sd_mk_431)
## 
##  Mann-Kendall trend test
## 
## data:  fall_standard_dev_all_431$sd_2
## z = 0.20634, n = 29, p-value = 0.8365
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##            S         varS          tau 
## 1.200000e+01 2.842000e+03 2.955665e-02
fall_sd_sens_431 <- sens.slope(fall_standard_dev_all_431$sd_2)
print(fall_sd_sens_431)
## 
##  Sen's slope
## 
## data:  fall_standard_dev_all_431$sd_2
## z = 0.20634, n = 29, p-value = 0.8365
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.04375436  0.04830897
## sample estimates:
## Sen's slope 
## 0.004665819

Spring and Fall SD CORRECTED

Spring

spring_standard_dev_all_431_ad <- standard_dev_431_ad %>% 
  filter(waterDay >= 183 & waterDay <= 243) %>%
  group_by(waterYear) %>% 
  mutate(nmbr = n())
spring_standard_dev_all_431_ad <- spring_standard_dev_all_431_ad %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)
spring_standard_dev_all_431_ad %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1989 3.311110
1993 3.443543
1995 3.397392
1996 4.607633
1997 4.284231
1998 4.514158
1999 4.562562
2000 4.312314
2001 4.145255
2002 3.042994
2003 4.446195
2004 3.465515
2005 3.941813
2006 3.486451
2007 3.444188
2008 4.019673
2009 4.561257
2010 4.347582
2011 4.081330
2012 3.676596
2013 4.103732
2015 2.710296
2016 3.536706
2017 4.041590
2018 3.755709
2019 3.143387
2020 3.695252
2021 3.349182
2022 4.106573
ggplot(spring_standard_dev_all_431_ad, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Morrisey-corrected standard deviation of SNOTEL 431 average spring temperatures for water years 1986-2021

spring MK & SS 431 (corrected)

spring_sd_mk_431_ad <- mk.test(spring_standard_dev_all_431_ad$sd_2)
print(spring_sd_mk_431_ad)
## 
##  Mann-Kendall trend test
## 
## data:  spring_standard_dev_all_431_ad$sd_2
## z = -0.99418, n = 29, p-value = 0.3201
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##            S         varS          tau 
##  -54.0000000 2842.0000000   -0.1330049
spring_sd_sens_431_ad <- sens.slope(spring_standard_dev_all_431_ad$sd_2)
print(spring_sd_sens_431_ad)
## 
##  Sen's slope
## 
## data:  spring_standard_dev_all_431_ad$sd_2
## z = -0.99418, n = 29, p-value = 0.3201
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.04050898  0.01029753
## sample estimates:
## Sen's slope 
## -0.01648253

Fall

fall_standard_dev_all_431_ad <- standard_dev_431_ad %>% 
  filter(waterDay >= 336 | waterDay <= 31) %>%
  group_by(waterYear) %>% 
  mutate(nmbr = n())
fall_standard_dev_all_431_ad <- fall_standard_dev_all_431_ad %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)
fall_standard_dev_all_431_ad %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1989 2.578899
1993 2.838846
1995 4.475022
1996 3.459867
1997 5.521310
1998 5.297586
1999 3.672922
2000 3.902052
2001 4.213677
2002 3.320336
2003 3.998034
2004 3.289939
2005 4.532367
2006 3.023908
2007 4.462579
2008 3.328614
2009 3.371658
2010 5.633056
2011 3.760958
2012 4.339709
2013 4.055962
2015 3.086069
2016 3.373025
2017 3.122956
2018 3.642421
2019 4.630803
2020 5.733839
2021 4.420807
2022 4.766119
ggplot(fall_standard_dev_all_431_ad, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Morrisey-corrected standard deviation of SNOTEL 431 average fall temperatures for water years 1986-2021. Note that the fall season is split by the water year.

fall MK & SS 431 (corrected)

fall_sd_mk_431_ad <- mk.test(fall_standard_dev_all_431_ad$sd_2)
print(fall_sd_mk_431_ad)
## 
##  Mann-Kendall trend test
## 
## data:  fall_standard_dev_all_431_ad$sd_2
## z = 1.2193, n = 29, p-value = 0.2227
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##            S         varS          tau 
##   66.0000000 2842.0000000    0.1625616
fall_sd_sens_431_ad <- sens.slope(fall_standard_dev_all_431_ad$sd_2)
print(fall_sd_sens_431_ad)
## 
##  Sen's slope
## 
## data:  fall_standard_dev_all_431_ad$sd_2
## z = 1.2193, n = 29, p-value = 0.2227
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.02038698  0.06405871
## sample estimates:
## Sen's slope 
##  0.02157689

Idarado 538

Morrisey 7/12/2004

snotel_538 <- SNOTEL_san_juan_Area %>% 
  filter(site_id == "538")
#str(snotel_538) # check the date, usually a character.  

snotel_538$Date <- as.Date(snotel_538$date) #change date from character to date format, capitalize to work with Water year functon from NWIS.

#THIS WILL CHANGE FOR EACH STATION
snotel_538_clean <- snotel_538 %>% # filter for the timeframe
  filter(Date >= "1979-10-01" & Date <= "2022-09-30") %>%
  #filter(temperature_mean >= -30 & temperature_mean <= 20) %>% # removing outliers   
  addWaterYear() %>% 
  mutate(daymonth = format(as.Date(Date), "%d-%m")) %>% 
  na.omit()

#adding water day using difftime (SUPER COOL. example from [this](https://stackoverflow.com/questions/48123049/create-day-index-based-on-water-year))

snotel_538_clean <- snotel_538_clean %>% 
  group_by(waterYear)%>% 
  mutate(waterDay = (as.integer(difftime(Date, ymd(paste0(waterYear - 1 ,'-09-30')), units = "days"))))
# Check for outliers

ggplot(snotel_538_clean, aes(x = Date, y = temperature_mean)) +
  geom_point() + #lwd = 2) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('Daily temperature (°C)') + 
  xlab('Date')

snotel_538_clean <- snotel_538_clean %>% 
  mutate(temp_diff = abs(temperature_min - temperature_max)) %>% 
  filter(temperature_mean > -40)# %>% 
  #filter(temperature_min < 25)
ggplot(snotel_538_clean, aes(x = Date, y = temp_diff)) + 
  geom_point() + #lwd = 2) +
  theme_few() +
  #geom_smooth(method = "lm", se=FALSE) +
  ylab('Daily temperature varience (°C)') + 
  xlab('Date')

Per Steven’s advice: :If there are more than 15 missing days, then…remove that year”

# filtering for temperature anomalies
snotel_538_cull_count <- snotel_538_clean %>% 
  filter(temperature_min > -40) %>% 
  count(waterYear)

snotel_538_cull_count
## # A tibble: 36 x 2
## # Groups:   waterYear [36]
##    waterYear     n
##        <dbl> <int>
##  1      1987   355
##  2      1988   366
##  3      1989   364
##  4      1990   365
##  5      1991   337
##  6      1992   358
##  7      1993   346
##  8      1994   351
##  9      1995   364
## 10      1996   365
## # ... with 26 more rows
# filtering for too few observations in a year
snotel_538_cull_count_days <- snotel_538_clean %>% 
  group_by(waterYear) %>% 
  count(waterYear) %>% 
  filter(n < 350)

snotel_538_cull_count_days
## # A tibble: 2 x 2
## # Groups:   waterYear [2]
##   waterYear     n
##       <dbl> <int>
## 1      1991   337
## 2      1993   346

1991 and 1993 need to be culled.

snotel_538_clean_culled <- snotel_538_clean %>% 
  filter(waterYear != "1991" & waterYear != "1993") # & waterYear != "1990" & waterYear != "1991" & waterYear != "1992" & waterYear != "1994" & waterYear != "2014") #%>% 
  #filter(temperature_mean > -49)
ggplot(snotel_538_clean_culled, aes(x = Date, y = temperature_mean)) + 
  geom_point() + #lwd = 2) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('Daily temperature (°C)') + 
  xlab('Date')

temp_538_xts <- xts(snotel_538_clean_culled$temperature_mean, order.by = snotel_538_clean_culled$Date)

dygraph(temp_538_xts) %>%
  dyAxis("y", label = "Daily mean temperature (°C)") 
snotel_538_clean_culled <- snotel_538_clean_culled %>% 
  filter(temperature_mean < 20)

temp_538_xts <- xts(snotel_538_clean_culled$temperature_mean, order.by = snotel_538_clean_culled$Date)

dygraph(temp_538_xts) %>%
  dyAxis("y", label = "Daily mean temperature (°C)") 

Idarado 538

Morrisey 7/12/2004

snotel_538_adjusted <- snotel_538_clean_culled %>%
  mutate(temp_ad = if_else(Date < "2004-07-12", ((5.3*10^(-7))*(temperature_mean^(4))+(3.72*10^(-5))*(temperature_mean^(3))-(2.16*10^(-3))*(temperature_mean^(2))-(7.32*10^(-2))*(temperature_mean)+1.37)+temperature_mean, temperature_mean))

Non-corrected

538 Detrended

#using the clean culled df:

#average water year temperature

yearly_wy_aver_538 <- snotel_538_adjusted %>% 
  group_by(waterYear) %>% 
  mutate(aver_ann_temp = mean(temperature_mean))

#Average temperature by day for all water years:

daily_wy_aver_538 <- yearly_wy_aver_538 %>% 
  group_by(daymonth) %>% 
  mutate(aver_day_temp = mean(aver_ann_temp))

#average mean temperature by day for the period of record:

daily_wy_aver_538 <- daily_wy_aver_538 %>% 
  group_by(daymonth) %>% 
  mutate(all_ave_temp = mean(daily_wy_aver_538$aver_day_temp))

# try to show all years as means. 
daily_wy_aver2_538 <-daily_wy_aver_538 %>% 
  group_by(waterDay) %>%
  mutate(date_temp = mean(temperature_mean))
  

daily_wy_aver2_538$date_temp <- signif(daily_wy_aver2_538$date_temp,3) #reduce the sig figs


ggplot(daily_wy_aver2_538, aes(x = waterDay, y = date_temp))+
  geom_line(size= 0.7) +
  theme_few() +
  ylab('Average Daily temperature (°C)') + 
  xlab('Day of water year')

538 SD

standard_dev_538 <- daily_wy_aver_538 %>% 
  group_by(waterYear) %>% 
  mutate(residual = (all_ave_temp-aver_ann_temp)+temperature_mean-aver_day_temp) %>% 
  mutate(deviation = abs(residual-lag(residual)))

standard_dev_all_538 <- standard_dev_538 %>% 
  group_by(waterYear) %>% 
  mutate(nmbr = n())

standard_dev_all_538 <- standard_dev_all_538 %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)

standard_dev_all_538 %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1987 8.006364
1988 8.601864
1989 8.632529
1990 8.392986
1992 7.829013
1994 10.169815
1995 7.658097
1996 7.925011
1997 7.934668
1998 8.455869
1999 7.252626
2000 7.992580
2001 8.428201
2002 8.883209
2003 8.309823
2004 8.066471
2005 7.228205
2006 7.518896
2007 7.890984
2008 8.117130
2009 7.048527
2010 8.062733
2011 7.859864
2012 7.787906
2013 8.410412
2014 7.465408
2015 6.906228
2016 7.611126
2017 7.235848
2018 7.239780
2019 7.718304
2020 7.976082
2021 8.027478
2022 7.664387
ggplot(standard_dev_all_538, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Non-corrected standard deviation of SNOTEL 538 average temperatures for water years 2005-2021

MK & SS for 538 (non-corrected)

sd_mk_538 <- mk.test(standard_dev_all_538$sd_2)
print(sd_mk_538)
## 
##  Mann-Kendall trend test
## 
## data:  standard_dev_all_538$sd_2
## z = -2.6684, n = 34, p-value = 0.007621
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##            S         varS          tau 
## -181.0000000 4550.3333333   -0.3226381
sd_sens_538 <- sens.slope(standard_dev_all_538$sd_2)
print(sd_sens_538)
## 
##  Sen's slope
## 
## data:  standard_dev_all_538$sd_2
## z = -2.6684, n = 34, p-value = 0.007621
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.042981556 -0.006896251
## sample estimates:
## Sen's slope 
## -0.02384088

Corrected

538 Detrended (corrected)

#using the clean culled df:
#average water year temperature
yearly_wy_aver_538_ad <- snotel_538_adjusted %>% 
  group_by(waterYear) %>% 
  mutate(aver_ann_temp_ad = mean(temp_ad))
#Average temperature by day for all water years:
daily_wy_aver_538_ad <- yearly_wy_aver_538_ad %>% 
  group_by(daymonth) %>% 
  mutate(aver_day_temp_ad = mean(aver_ann_temp_ad))
#average mean temperature by day for the period of record:
daily_wy_aver_538_ad <- daily_wy_aver_538_ad %>% 
  group_by(daymonth) %>% 
  mutate(all_ave_temp_ad = mean(daily_wy_aver_538_ad$aver_day_temp_ad))
# try to show all years as means. 
daily_wy_aver2_538_ad <-daily_wy_aver_538_ad %>% 
  group_by(waterDay) %>%
  mutate(date_temp_ad = mean(temp_ad))
  
daily_wy_aver2_538_ad$date_temp_ad <- signif(daily_wy_aver2_538_ad$date_temp_ad,3) #reduce the sig figs
ggplot(daily_wy_aver2_538_ad, aes(x = waterDay, y = date_temp_ad))+
  geom_line(size= 0.7) +
  theme_few() +
  ylab('Average Daily temperature (°C)') + 
  xlab('Day of water year')

538 SS (corrected)

standard_dev_538_ad <- daily_wy_aver_538_ad %>% 
  group_by(waterYear) %>% 
  #filter(waterYear >= 1987 & waterYear <= 2021) %>% 
  mutate(residual = (all_ave_temp_ad-aver_ann_temp_ad)+temp_ad-aver_day_temp_ad) %>% 
  mutate(deviation = abs(residual-lag(residual)))
standard_dev_all_538_ad <- standard_dev_538_ad %>% 
  group_by(waterYear) %>% 
  mutate(nmbr = n())
standard_dev_all_538_ad <- standard_dev_all_538_ad %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)
standard_dev_all_538_ad %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1987 7.447584
1988 8.019241
1989 8.069873
1990 7.812557
1992 7.272544
1994 9.549437
1995 7.113641
1996 7.353811
1997 7.396458
1998 7.860736
1999 6.739299
2000 7.408528
2001 7.835100
2002 8.260161
2003 7.706375
2004 7.450714
2005 7.228187
2006 7.519259
2007 7.891254
2008 8.117349
2009 7.048722
2010 8.062844
2011 7.860215
2012 7.788573
2013 8.411054
2014 7.465688
2015 6.906947
2016 7.611742
2017 7.235817
2018 7.240024
2019 7.718445
2020 7.976612
2021 8.027693
2022 7.664991
ggplot(standard_dev_all_538_ad, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Morrisey-corrected standard deviation of SNOTEL 538 average temperatures for water years 1986-2021

MK & SS 538 (corrected)

sd_mk_538_ad <- mk.test(standard_dev_all_538_ad$sd_2)
print(sd_mk_538_ad)
## 
##  Mann-Kendall trend test
## 
## data:  standard_dev_all_538_ad$sd_2
## z = 0.14824, n = 34, p-value = 0.8821
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##            S         varS          tau 
## 1.100000e+01 4.550333e+03 1.960784e-02
sd_sens_538_ad <- sens.slope(standard_dev_all_538_ad$sd_2)
print(sd_sens_538_ad)
## 
##  Sen's slope
## 
## data:  standard_dev_all_538_ad$sd_2
## z = 0.14824, n = 34, p-value = 0.8821
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.01508416  0.01703536
## sample estimates:
##  Sen's slope 
## 0.0009105465

Summer and Winter SD NOT-CORRECTED

Summer

summer_standard_dev_all_538 <- standard_dev_538 %>%
  filter(waterDay >= 244 & waterDay <= 335) %>%
  group_by(waterYear) %>% 
  mutate(nmbr = n())

summer_standard_dev_all_538 <- summer_standard_dev_all_538 %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)

summer_standard_dev_all_538 %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1987 2.286005
1988 2.273513
1989 3.233122
1990 2.664477
1992 2.736380
1994 1.935542
1995 3.113265
1996 1.898021
1997 2.007429
1998 2.790447
1999 2.372218
2000 1.860330
2001 2.400933
2002 2.466890
2003 2.718293
2004 2.323215
2005 2.806529
2006 1.918794
2007 2.183218
2008 2.300074
2009 2.431260
2010 2.191297
2011 1.862060
2012 1.694107
2013 2.005642
2014 1.961264
2015 2.139016
2016 2.301314
2017 1.746921
2018 1.640625
2019 2.266448
2020 2.256431
2021 2.070257
2022 1.944235
ggplot(summer_standard_dev_all_538, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Non-corrected standard deviation of SNOTEL 538 average summer temperatures for water years 2005-2021

summer MK & SS for 538 (non-corrected)

summer_sd_mk_538 <- mk.test(summer_standard_dev_all_538$sd_2)
print(summer_sd_mk_538)
## 
##  Mann-Kendall trend test
## 
## data:  summer_standard_dev_all_538$sd_2
## z = -2.698, n = 34, p-value = 0.006975
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##            S         varS          tau 
## -183.0000000 4550.3333333   -0.3262032
summer_sd_sens_538 <- sens.slope(summer_standard_dev_all_538$sd_2)
print(summer_sd_sens_538)
## 
##  Sen's slope
## 
## data:  summer_standard_dev_all_538$sd_2
## z = -2.698, n = 34, p-value = 0.006975
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.033679036 -0.005513698
## sample estimates:
## Sen's slope 
## -0.01860794

Winter

winter_standard_dev_all_538 <- standard_dev_538 %>%
  filter(waterDay >= 32 & waterDay <= 182) %>%
  group_by(waterYear) %>% 
  mutate(nmbr = n())

winter_standard_dev_all_538 <- winter_standard_dev_all_538 %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)

winter_standard_dev_all_538 %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1987 4.261954
1988 5.174663
1989 6.182112
1990 5.129029
1992 4.206723
1994 5.619481
1995 4.701116
1996 4.620550
1997 5.021863
1998 4.465685
1999 4.642997
2000 4.872329
2001 4.227546
2002 5.161789
2003 4.232413
2004 5.464700
2005 4.007572
2006 4.830993
2007 5.347082
2008 5.517212
2009 4.330423
2010 4.438182
2011 5.393996
2012 4.319554
2013 5.628011
2014 4.325964
2015 4.611312
2016 4.735485
2017 5.218358
2018 4.425586
2019 4.275462
2020 4.587430
2021 4.421560
2022 4.624955
ggplot(winter_standard_dev_all_538, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Non-corrected standard deviation of SNOTEL 538 average winter temperatures for water years 2005-2021

winter MK & SS for 538 (non-corrected)

winter_sd_mk_538 <- mk.test(winter_standard_dev_all_538$sd_2)
print(winter_sd_mk_538)
## 
##  Mann-Kendall trend test
## 
## data:  winter_standard_dev_all_538$sd_2
## z = -0.80052, n = 34, p-value = 0.4234
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##             S          varS           tau 
##  -55.00000000 4550.33333333   -0.09803922
winter_sd_sens_538 <- sens.slope(winter_standard_dev_all_538$sd_2)
print(winter_sd_sens_538)
## 
##  Sen's slope
## 
## data:  winter_standard_dev_all_538$sd_2
## z = -0.80052, n = 34, p-value = 0.4234
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.026752749  0.009824772
## sample estimates:
##  Sen's slope 
## -0.008862001

Summer and Winter SD CORRECTED

Summer

summer_standard_dev_all_538_ad <- standard_dev_538_ad %>% 
  filter(waterDay >= 244 & waterDay <= 335) %>%
  group_by(waterYear) %>% 
  mutate(nmbr = n())
summer_standard_dev_all_538_ad <- summer_standard_dev_all_538_ad %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)
summer_standard_dev_all_538_ad %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1987 2.055839
1988 2.049493
1989 2.902440
1990 2.396673
1992 2.463107
1994 1.734275
1995 2.798052
1996 1.701215
1997 1.804148
1998 2.508680
1999 2.138026
2000 1.664807
2001 2.163899
2002 2.210401
2003 2.435307
2004 2.160957
2005 2.805521
2006 1.919561
2007 2.184205
2008 2.299542
2009 2.430957
2010 2.190804
2011 1.862764
2012 1.698114
2013 2.007185
2014 1.961864
2015 2.142038
2016 2.302889
2017 1.748470
2018 1.641454
2019 2.263670
2020 2.256562
2021 2.068673
2022 1.943594
ggplot(summer_standard_dev_all_538_ad, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Morrisey-corrected standard deviation of SNOTEL 538 average summer temperatures for water years 1986-2021

summer MK & SS 538 (corrected)

summer_sd_mk_538_ad <- mk.test(summer_standard_dev_all_538_ad$sd_2)
print(summer_sd_mk_538_ad)
## 
##  Mann-Kendall trend test
## 
## data:  summer_standard_dev_all_538_ad$sd_2
## z = -1.186, n = 34, p-value = 0.2356
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##           S        varS         tau 
##  -81.000000 4550.333333   -0.144385
summer_sd_sens_538_ad <- sens.slope(summer_standard_dev_all_538_ad$sd_2)
print(summer_sd_sens_538_ad)
## 
##  Sen's slope
## 
## data:  summer_standard_dev_all_538_ad$sd_2
## z = -1.186, n = 34, p-value = 0.2356
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.020711408  0.005565886
## sample estimates:
## Sen's slope 
## -0.00764982

Winter

winter_standard_dev_all_538_ad <- standard_dev_538_ad %>% 
  filter(waterDay >= 32 & waterDay <= 182) %>%
  group_by(waterYear) %>% 
  mutate(nmbr = n())
winter_standard_dev_all_538_ad <- winter_standard_dev_all_538_ad %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)
winter_standard_dev_all_538_ad %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1987 4.109307
1988 4.994440
1989 5.973268
1990 4.943886
1992 4.047152
1994 5.487129
1995 4.504527
1996 4.445704
1997 4.843480
1998 4.304597
1999 4.457758
2000 4.678027
2001 4.085048
2002 4.972893
2003 4.083408
2004 5.267994
2005 4.007627
2006 4.830574
2007 5.346512
2008 5.515768
2009 4.329745
2010 4.437191
2011 5.393419
2012 4.319038
2013 5.628675
2014 4.325676
2015 4.611280
2016 4.734318
2017 5.216960
2018 4.424429
2019 4.274306
2020 4.586853
2021 4.421444
2022 4.625350
ggplot(winter_standard_dev_all_538_ad, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Morrisey-corrected standard deviation of SNOTEL 538 average winter temperatures for water years 1986-2021

winter MK & SS 538 (corrected)

winter_sd_mk_538_ad <- mk.test(winter_standard_dev_all_538_ad$sd_2)
print(winter_sd_mk_538_ad)
## 
##  Mann-Kendall trend test
## 
## data:  winter_standard_dev_all_538_ad$sd_2
## z = -0.26684, n = 34, p-value = 0.7896
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##             S          varS           tau 
##  -19.00000000 4550.33333333   -0.03386809
winter_sd_sens_538_ad <- sens.slope(winter_standard_dev_all_538_ad$sd_2)
print(winter_sd_sens_538_ad)
## 
##  Sen's slope
## 
## data:  winter_standard_dev_all_538_ad$sd_2
## z = -0.26684, n = 34, p-value = 0.7896
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.01995480  0.01766204
## sample estimates:
##  Sen's slope 
## -0.001595321

Spring and Fall SD NOT-CORRECTED

Spring

spring_standard_dev_all_538 <- standard_dev_538 %>%
  filter(waterDay >= 183 & waterDay <= 243) %>%
  group_by(waterYear) %>% 
  mutate(nmbr = n())

spring_standard_dev_all_538 <- spring_standard_dev_all_538 %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)

spring_standard_dev_all_538 %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1987 3.552716
1988 4.455530
1989 3.982128
1990 3.466124
1992 2.998761
1994 4.353420
1995 3.388139
1996 4.947973
1997 4.811100
1998 4.442438
1999 4.542943
2000 4.364296
2001 4.176415
2002 3.254748
2003 4.619182
2004 3.409377
2005 4.066343
2006 3.444060
2007 3.354023
2008 4.234953
2009 4.413089
2010 4.502572
2011 4.155985
2012 3.631028
2013 4.436077
2014 4.386135
2015 2.646767
2016 3.273821
2017 3.787707
2018 3.892130
2019 2.939245
2020 3.919491
2021 3.207055
2022 4.234419
ggplot(spring_standard_dev_all_538, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Non-corrected standard deviation of SNOTEL 538 average spring temperatures for water years 2005-2021

spring MK & SS for 538 (non-corrected)

spring_sd_mk_538 <- mk.test(spring_standard_dev_all_538$sd_2)
print(spring_sd_mk_538)
## 
##  Mann-Kendall trend test
## 
## data:  spring_standard_dev_all_538$sd_2
## z = -1.4231, n = 34, p-value = 0.1547
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##            S         varS          tau 
##  -97.0000000 4550.3333333   -0.1729055
spring_sd_sens_538 <- sens.slope(spring_standard_dev_all_538$sd_2)
print(spring_sd_sens_538)
## 
##  Sen's slope
## 
## data:  spring_standard_dev_all_538$sd_2
## z = -1.4231, n = 34, p-value = 0.1547
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.033167579  0.008138418
## sample estimates:
## Sen's slope 
## -0.01352231

Fall

Fall is split each water year in the middle of the season. This analysis splits the fall season between the preceding water year and the subsequent water year.

fall_standard_dev_all_538 <- standard_dev_538 %>%
  filter(waterDay >= 336 | waterDay <= 31) %>% 
  group_by(waterYear) %>% 
  mutate(nmbr = n())

fall_standard_dev_all_538 <- fall_standard_dev_all_538 %>% 
  #group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)

fall_standard_dev_all_538 %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1987 3.242010
1988 3.208635
1989 3.190905
1990 5.015374
1992 5.230548
1994 11.013370
1995 4.306300
1996 4.250373
1997 5.400857
1998 5.530556
1999 3.559163
2000 4.228433
2001 3.996027
2002 3.736982
2003 3.953813
2004 3.594849
2005 3.970198
2006 3.019711
2007 4.712983
2008 3.777457
2009 3.692159
2010 5.280824
2011 3.642980
2012 4.173179
2013 4.224198
2014 4.836061
2015 3.064942
2016 3.180620
2017 3.413380
2018 3.759743
2019 4.482426
2020 5.900624
2021 4.736382
2022 4.807596
ggplot(fall_standard_dev_all_538, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Non-corrected standard deviation of SNOTEL 538 average fall temperatures for water years 2005-2021. Note that the season is split by the water year.

fall MK & SS for 538 (non-corrected)

fall_sd_mk_538 <- mk.test(fall_standard_dev_all_538$sd_2)
print(fall_sd_mk_538)
## 
##  Mann-Kendall trend test
## 
## data:  fall_standard_dev_all_538$sd_2
## z = 0.029649, n = 34, p-value = 0.9763
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##            S         varS          tau 
## 3.000000e+00 4.550333e+03 5.347594e-03
fall_sd_sens_538 <- sens.slope(fall_standard_dev_all_538$sd_2)
print(fall_sd_sens_538)
## 
##  Sen's slope
## 
## data:  fall_standard_dev_all_538$sd_2
## z = 0.029649, n = 34, p-value = 0.9763
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.03767506  0.03894759
## sample estimates:
## Sen's slope 
## 0.001671398

Spring and Fall SD CORRECTED

Spring

spring_standard_dev_all_538_ad <- standard_dev_538_ad %>% 
  filter(waterDay >= 183 & waterDay <= 243) %>%
  group_by(waterYear) %>% 
  mutate(nmbr = n())
spring_standard_dev_all_538_ad <- spring_standard_dev_all_538_ad %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)
spring_standard_dev_all_538_ad %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1987 3.271026
1988 4.099402
1989 3.636849
1990 3.191423
1992 2.738760
1994 4.001009
1995 3.138036
1996 4.546852
1997 4.485082
1998 4.094696
1999 4.209681
2000 3.986982
2001 3.836395
2002 2.956881
2003 4.235226
2004 3.121317
2005 4.065979
2006 3.443427
2007 3.353806
2008 4.234129
2009 4.412192
2010 4.502440
2011 4.155762
2012 3.631159
2013 4.435896
2014 4.386036
2015 2.645292
2016 3.273225
2017 3.787134
2018 3.892409
2019 2.939616
2020 3.919557
2021 3.206337
2022 4.234251
ggplot(spring_standard_dev_all_538_ad, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Morrisey-corrected standard deviation of SNOTEL 538 average spring temperatures for water years 1986-2021

spring MK & SS 538 (corrected)

spring_sd_mk_538_ad <- mk.test(spring_standard_dev_all_538_ad$sd_2)
print(spring_sd_mk_538_ad)
## 
##  Mann-Kendall trend test
## 
## data:  spring_standard_dev_all_538_ad$sd_2
## z = 0.088947, n = 34, p-value = 0.9291
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##            S         varS          tau 
## 7.000000e+00 4.550333e+03 1.247772e-02
spring_sd_sens_538_ad <- sens.slope(spring_standard_dev_all_538_ad$sd_2)
print(spring_sd_sens_538_ad)
## 
##  Sen's slope
## 
## data:  spring_standard_dev_all_538_ad$sd_2
## z = 0.088947, n = 34, p-value = 0.9291
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.02216506  0.02423561
## sample estimates:
## Sen's slope 
## 0.001068265

Fall

fall_standard_dev_all_538_ad <- standard_dev_538_ad %>% 
  filter(waterDay >= 336 | waterDay <= 31) %>%
  group_by(waterYear) %>% 
  mutate(nmbr = n())
fall_standard_dev_all_538_ad <- fall_standard_dev_all_538_ad %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)
fall_standard_dev_all_538_ad %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1987 2.978889
1988 2.918518
1989 2.890054
1990 4.600921
1992 4.836907
1994 10.459305
1995 3.926013
1996 3.890020
1997 4.985669
1998 5.090325
1999 3.260154
2000 3.864410
2001 3.645234
2002 3.413027
2003 3.618162
2004 3.274445
2005 3.968117
2006 3.020667
2007 4.712269
2008 3.777243
2009 3.691768
2010 5.279353
2011 3.643188
2012 4.171729
2013 4.222004
2014 4.834177
2015 3.063534
2016 3.180308
2017 3.410281
2018 3.759079
2019 4.482340
2020 5.900827
2021 4.734334
2022 4.807242
ggplot(fall_standard_dev_all_538_ad, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Morrisey-corrected standard deviation of SNOTEL 538 average fall temperatures for water years 1986-2021. Note that the fall season is split by the water year.

fall MK & SS 538 (corrected)

fall_sd_mk_538_ad <- mk.test(fall_standard_dev_all_538_ad$sd_2)
print(fall_sd_mk_538_ad)
## 
##  Mann-Kendall trend test
## 
## data:  fall_standard_dev_all_538_ad$sd_2
## z = 1.097, n = 34, p-value = 0.2726
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##            S         varS          tau 
##   75.0000000 4550.3333333    0.1336898
fall_sd_sens_538_ad <- sens.slope(fall_standard_dev_all_538_ad$sd_2)
print(fall_sd_sens_538_ad)
## 
##  Sen's slope
## 
## data:  fall_standard_dev_all_538_ad$sd_2
## z = 1.097, n = 34, p-value = 0.2726
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.01525014  0.05179645
## sample estimates:
## Sen's slope 
##  0.01952845

Lone Cone 589

Oyler -> Morrisey 6/22/2005

snotel_589 <- SNOTEL_san_juan_Area %>% 
  filter(site_id == "589")
#str(snotel_589) # check the date, usually a character.  

snotel_589$Date <- as.Date(snotel_589$date) #change date from character to date format, capitalize to work with Water year functon from NWIS.

#THIS WILL CHANGE FOR EACH STATION
snotel_589_clean <- snotel_589 %>% # filter for the timeframe
  filter(Date >= "1979-10-01" & Date <= "2022-09-30") %>%
  #filter(temperature_mean >= -30 & temperature_mean <= 20) %>% # removing outliers   
  addWaterYear() %>% 
  mutate(daymonth = format(as.Date(Date), "%d-%m")) %>% 
  na.omit()

#adding water day using difftime (SUPER COOL. example from [this](https://stackoverflow.com/questions/48123049/create-day-index-based-on-water-year))

snotel_589_clean <- snotel_589_clean %>% 
  group_by(waterYear)%>% 
  mutate(waterDay = (as.integer(difftime(Date, ymd(paste0(waterYear - 1 ,'-09-30')), units = "days"))))
# Check for outliers

ggplot(snotel_589_clean, aes(x = Date, y = temperature_mean)) +
  geom_point() + #lwd = 2) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('Daily temperature (°C)') + 
  xlab('Date')

snotel_589_clean <- snotel_589_clean %>% 
  mutate(temp_diff = abs(temperature_min - temperature_max)) %>% 
  filter(temperature_mean > -40)# %>% 
  #filter(temperature_min < 25)
ggplot(snotel_589_clean, aes(x = Date, y = temp_diff)) + 
  geom_point() + #lwd = 2) +
  theme_few() +
  #geom_smooth(method = "lm", se=FALSE) +
  ylab('Daily temperature varience (°C)') + 
  xlab('Date')

Per Steven’s advice: :If there are more than 15 missing days, then…remove that year”

# filtering for temperature anomalies
snotel_589_cull_count <- snotel_589_clean %>% 
  filter(temperature_min > -40) %>% 
  count(waterYear)

snotel_589_cull_count
## # A tibble: 37 x 2
## # Groups:   waterYear [37]
##    waterYear     n
##        <dbl> <int>
##  1      1986     1
##  2      1987   358
##  3      1988   366
##  4      1989   362
##  5      1990   365
##  6      1991   359
##  7      1992   366
##  8      1993   350
##  9      1994   337
## 10      1995   364
## # ... with 27 more rows
# filtering for too few observations in a year
snotel_589_cull_count_days <- snotel_589_clean %>% 
  group_by(waterYear) %>% 
  count(waterYear) %>% 
  filter(n < 350)

snotel_589_cull_count_days
## # A tibble: 10 x 2
## # Groups:   waterYear [10]
##    waterYear     n
##        <dbl> <int>
##  1      1986     1
##  2      1994   337
##  3      1997   346
##  4      2006   317
##  5      2009   314
##  6      2010   332
##  7      2011   309
##  8      2012   322
##  9      2013   331
## 10      2014   335

1986, 1994, 1997, 2006, 2009, 2010, 2011, 2012, 2013, 2014 need to be culled.

snotel_589_clean_culled <- snotel_589_clean %>% 
  filter(waterYear != "1986" & waterYear != "1994" & waterYear != "1997" & waterYear != "2006" & waterYear != "2009" & waterYear != "2010" & waterYear != "2011" & waterYear != "2012" & waterYear != "2013" & waterYear != "2014") #%>% 
  #filter(temperature_mean > -49)
ggplot(snotel_589_clean_culled, aes(x = Date, y = temperature_mean)) + 
  geom_point() + #lwd = 2) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('Daily temperature (°C)') + 
  xlab('Date')

temp_589_xts <- xts(snotel_589_clean_culled$temperature_mean, order.by = snotel_589_clean_culled$Date)

dygraph(temp_589_xts) %>%
  dyAxis("y", label = "Daily mean temperature (°C)") 
snotel_589_clean_culled <- snotel_589_clean_culled %>% 
  filter(temperature_mean < 20)

temp_589_xts <- xts(snotel_589_clean_culled$temperature_mean, order.by = snotel_589_clean_culled$Date)

dygraph(temp_589_xts) %>%
  dyAxis("y", label = "Daily mean temperature (°C)") 

Lone Cone 589

Oyler -> Morrisey 6/22/2005

snotel_589_adjusted <- snotel_589_clean_culled %>%
  mutate(temp_ad = if_else(Date < "2005-06-22", ((5.3*10^(-7))*(temperature_mean^(4))+(3.72*10^(-5))*(temperature_mean^(3))-(2.16*10^(-3))*(temperature_mean^(2))-(7.32*10^(-2))*(temperature_mean)+1.37)+temperature_mean, temperature_mean))

Non-corrected

589 Detrended

#using the clean culled df:

#average water year temperature

yearly_wy_aver_589 <- snotel_589_adjusted %>% 
  group_by(waterYear) %>% 
  mutate(aver_ann_temp = mean(temperature_mean))

#Average temperature by day for all water years:

daily_wy_aver_589 <- yearly_wy_aver_589 %>% 
  group_by(daymonth) %>% 
  mutate(aver_day_temp = mean(aver_ann_temp))

#average mean temperature by day for the period of record:

daily_wy_aver_589 <- daily_wy_aver_589 %>% 
  group_by(daymonth) %>% 
  mutate(all_ave_temp = mean(daily_wy_aver_589$aver_day_temp))

# try to show all years as means. 
daily_wy_aver2_589 <-daily_wy_aver_589 %>% 
  group_by(waterDay) %>%
  mutate(date_temp = mean(temperature_mean))
  

daily_wy_aver2_589$date_temp <- signif(daily_wy_aver2_589$date_temp,3) #reduce the sig figs


ggplot(daily_wy_aver2_589, aes(x = waterDay, y = date_temp))+
  geom_line(size= 0.7) +
  theme_few() +
  ylab('Average Daily temperature (°C)') + 
  xlab('Day of water year')

589 SD

standard_dev_589 <- daily_wy_aver_589 %>% 
  group_by(waterYear) %>% 
  mutate(residual = (all_ave_temp-aver_ann_temp)+temperature_mean-aver_day_temp) %>% 
  mutate(deviation = abs(residual-lag(residual)))

standard_dev_all_589 <- standard_dev_589 %>% 
  group_by(waterYear) %>% 
  mutate(nmbr = n())

standard_dev_all_589 <- standard_dev_all_589 %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)

standard_dev_all_589 %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1987 8.224944
1988 8.773281
1989 8.776693
1990 8.580289
1991 8.502502
1992 7.975611
1993 8.199081
1995 7.946318
1996 8.231469
1998 8.706109
1999 7.431979
2000 8.232988
2001 8.771085
2002 9.082003
2003 8.732769
2004 8.380419
2005 8.458900
2007 8.212611
2008 8.408220
2015 7.103666
2016 7.842413
2017 7.527960
2018 7.506884
2019 8.029199
2020 8.271099
2021 8.278625
2022 8.020852
ggplot(standard_dev_all_589, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Non-corrected standard deviation of SNOTEL 589 average temperatures for water years 2005-2021

MK & SS for 589 (non-corrected)

sd_mk_589 <- mk.test(standard_dev_all_589$sd_2)
print(sd_mk_589)
## 
##  Mann-Kendall trend test
## 
## data:  standard_dev_all_589$sd_2
## z = -1.8345, n = 27, p-value = 0.06658
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##            S         varS          tau 
##  -89.0000000 2301.0000000   -0.2535613
sd_sens_589 <- sens.slope(standard_dev_all_589$sd_2)
print(sd_sens_589)
## 
##  Sen's slope
## 
## data:  standard_dev_all_589$sd_2
## z = -1.8345, n = 27, p-value = 0.06658
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.043902404  0.001230005
## sample estimates:
## Sen's slope 
## -0.02183399

Corrected

589 Detrended (corrected)

#using the clean culled df:
#average water year temperature
yearly_wy_aver_589_ad <- snotel_589_adjusted %>% 
  group_by(waterYear) %>% 
  mutate(aver_ann_temp_ad = mean(temp_ad))
#Average temperature by day for all water years:
daily_wy_aver_589_ad <- yearly_wy_aver_589_ad %>% 
  group_by(daymonth) %>% 
  mutate(aver_day_temp_ad = mean(aver_ann_temp_ad))
#average mean temperature by day for the period of record:
daily_wy_aver_589_ad <- daily_wy_aver_589_ad %>% 
  group_by(daymonth) %>% 
  mutate(all_ave_temp_ad = mean(daily_wy_aver_589_ad$aver_day_temp_ad))
# try to show all years as means. 
daily_wy_aver2_589_ad <-daily_wy_aver_589_ad %>% 
  group_by(waterDay) %>%
  mutate(date_temp_ad = mean(temp_ad))
  
daily_wy_aver2_589_ad$date_temp_ad <- signif(daily_wy_aver2_589_ad$date_temp_ad,3) #reduce the sig figs
ggplot(daily_wy_aver2_589_ad, aes(x = waterDay, y = date_temp_ad))+
  geom_line(size= 0.7) +
  theme_few() +
  ylab('Average Daily temperature (°C)') + 
  xlab('Day of water year')

589 SS (corrected)

standard_dev_589_ad <- daily_wy_aver_589_ad %>% 
  group_by(waterYear) %>% 
  #filter(waterYear >= 1987 & waterYear <= 2021) %>% 
  mutate(residual = (all_ave_temp_ad-aver_ann_temp_ad)+temp_ad-aver_day_temp_ad) %>% 
  mutate(deviation = abs(residual-lag(residual)))
standard_dev_all_589_ad <- standard_dev_589_ad %>% 
  group_by(waterYear) %>% 
  mutate(nmbr = n())
standard_dev_all_589_ad <- standard_dev_all_589_ad %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)
standard_dev_all_589_ad %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1987 7.671688
1988 8.200568
1989 8.222864
1990 7.999469
1991 7.962227
1992 7.420415
1993 7.639311
1995 7.378994
1996 7.641722
1998 8.086353
1999 6.914950
2000 7.633161
2001 8.156564
2002 8.440080
2003 8.103839
2004 7.827141
2005 7.781158
2007 8.212720
2008 8.408841
2015 7.104293
2016 7.842763
2017 7.527954
2018 7.507329
2019 8.029667
2020 8.271310
2021 8.278726
2022 8.021229
ggplot(standard_dev_all_589_ad, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Morrisey-corrected standard deviation of SNOTEL 589 average temperatures for water years 1986-2021

MK & SS 589 (corrected)

sd_mk_589_ad <- mk.test(standard_dev_all_589_ad$sd_2)
print(sd_mk_589_ad)
## 
##  Mann-Kendall trend test
## 
## data:  standard_dev_all_589_ad$sd_2
## z = 0.6671, n = 27, p-value = 0.5047
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##            S         varS          tau 
## 3.300000e+01 2.301000e+03 9.401709e-02
sd_sens_589_ad <- sens.slope(standard_dev_all_589_ad$sd_2)
print(sd_sens_589_ad)
## 
##  Sen's slope
## 
## data:  standard_dev_all_589_ad$sd_2
## z = 0.6671, n = 27, p-value = 0.5047
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.01153608  0.02498422
## sample estimates:
## Sen's slope 
## 0.008250776

Summer and Winter SD NOT-CORRECTED

Summer

summer_standard_dev_all_589 <- standard_dev_589 %>%
  filter(waterDay >= 244 & waterDay <= 335) %>%
  group_by(waterYear) %>% 
  mutate(nmbr = n())

summer_standard_dev_all_589 <- summer_standard_dev_all_589 %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)

summer_standard_dev_all_589 %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1987 1.967742
1988 2.534636
1989 3.461696
1990 2.403263
1991 2.525811
1992 2.623689
1993 3.041407
1995 3.367172
1996 2.111391
1998 2.893363
1999 2.622980
2000 1.957874
2001 2.664325
2002 2.647149
2003 2.840568
2004 2.383584
2005 3.230216
2007 2.297878
2008 2.318882
2015 2.142048
2016 2.374472
2017 1.826211
2018 1.691936
2019 2.406265
2020 2.368206
2021 2.273992
2022 2.104514
ggplot(summer_standard_dev_all_589, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Non-corrected standard deviation of SNOTEL 589 average summer temperatures for water years 2005-2021

summer MK & SS for 589 (non-corrected)

summer_sd_mk_589 <- mk.test(summer_standard_dev_all_589$sd_2)
print(summer_sd_mk_589)
## 
##  Mann-Kendall trend test
## 
## data:  summer_standard_dev_all_589$sd_2
## z = -2.2515, n = 27, p-value = 0.02436
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##            S         varS          tau 
## -109.0000000 2301.0000000   -0.3105413
summer_sd_sens_589 <- sens.slope(summer_standard_dev_all_589$sd_2)
print(summer_sd_sens_589)
## 
##  Sen's slope
## 
## data:  summer_standard_dev_all_589$sd_2
## z = -2.2515, n = 27, p-value = 0.02436
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.049347872 -0.001693607
## sample estimates:
## Sen's slope 
## -0.02326586

Winter

winter_standard_dev_all_589 <- standard_dev_589 %>%
  filter(waterDay >= 32 & waterDay <= 182) %>%
  group_by(waterYear) %>% 
  mutate(nmbr = n())

winter_standard_dev_all_589 <- winter_standard_dev_all_589 %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)

winter_standard_dev_all_589 %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1987 4.353379
1988 5.361949
1989 6.315764
1990 5.337449
1991 5.180784
1992 4.169408
1993 4.454775
1995 4.870066
1996 4.842621
1998 4.523873
1999 4.971961
2000 5.060819
2001 4.408432
2002 5.356568
2003 4.383529
2004 5.881583
2005 4.319148
2007 5.569424
2008 5.616044
2015 4.729116
2016 4.857060
2017 5.445588
2018 4.504100
2019 4.213170
2020 4.673225
2021 4.620711
2022 4.838951
ggplot(winter_standard_dev_all_589, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Non-corrected standard deviation of SNOTEL 589 average winter temperatures for water years 2005-2021

winter MK & SS for 589 (non-corrected)

winter_sd_mk_589 <- mk.test(winter_standard_dev_all_589$sd_2)
print(winter_sd_mk_589)
## 
##  Mann-Kendall trend test
## 
## data:  winter_standard_dev_all_589$sd_2
## z = -0.62541, n = 27, p-value = 0.5317
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##             S          varS           tau 
##  -31.00000000 2301.00000000   -0.08831909
winter_sd_sens_589 <- sens.slope(winter_standard_dev_all_589$sd_2)
print(winter_sd_sens_589)
## 
##  Sen's slope
## 
## data:  winter_standard_dev_all_589$sd_2
## z = -0.62541, n = 27, p-value = 0.5317
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.03759354  0.01968776
## sample estimates:
## Sen's slope 
## -0.01157889

Summer and Winter SD CORRECTED

Summer

summer_standard_dev_all_589_ad <- standard_dev_589_ad %>% 
  filter(waterDay >= 244 & waterDay <= 335) %>%
  group_by(waterYear) %>% 
  mutate(nmbr = n())
summer_standard_dev_all_589_ad <- summer_standard_dev_all_589_ad %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)
summer_standard_dev_all_589_ad %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1987 1.766231
1988 2.285505
1989 3.125668
1990 2.158914
1991 2.282519
1992 2.358745
1993 2.738134
1995 3.026153
1996 1.891330
1998 2.601086
1999 2.364119
2000 1.751532
2001 2.401863
2002 2.373286
2003 2.546455
2004 2.136727
2005 2.993266
2007 2.299972
2008 2.319300
2015 2.145049
2016 2.375700
2017 1.827998
2018 1.692844
2019 2.406014
2020 2.368208
2021 2.271396
2022 2.103934
ggplot(summer_standard_dev_all_589_ad, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Morrisey-corrected standard deviation of SNOTEL 589 average summer temperatures for water years 1986-2021

summer MK & SS 589 (corrected)

summer_sd_mk_589_ad <- mk.test(summer_standard_dev_all_589_ad$sd_2)
print(summer_sd_mk_589_ad)
## 
##  Mann-Kendall trend test
## 
## data:  summer_standard_dev_all_589_ad$sd_2
## z = -0.83388, n = 27, p-value = 0.4044
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##            S         varS          tau 
##  -41.0000000 2301.0000000   -0.1168091
summer_sd_sens_589_ad <- sens.slope(summer_standard_dev_all_589_ad$sd_2)
print(summer_sd_sens_589_ad)
## 
##  Sen's slope
## 
## data:  summer_standard_dev_all_589_ad$sd_2
## z = -0.83388, n = 27, p-value = 0.4044
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.02845926  0.00764659
## sample estimates:
## Sen's slope 
## -0.00560237

Winter

winter_standard_dev_all_589_ad <- standard_dev_589_ad %>% 
  filter(waterDay >= 32 & waterDay <= 182) %>%
  group_by(waterYear) %>% 
  mutate(nmbr = n())
winter_standard_dev_all_589_ad <- winter_standard_dev_all_589_ad %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)
winter_standard_dev_all_589_ad %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1987 4.215611
1988 5.197066
1989 6.124702
1990 5.163969
1991 5.065782
1992 4.018647
1993 4.309492
1995 4.680477
1996 4.671648
1998 4.353429
1999 4.771281
2000 4.857137
2001 4.272848
2002 5.152772
2003 4.243131
2004 5.666034
2005 4.181523
2007 5.567999
2008 5.616390
2015 4.728585
2016 4.856335
2017 5.443448
2018 4.503520
2019 4.213250
2020 4.672479
2021 4.619604
2022 4.838898
ggplot(winter_standard_dev_all_589_ad, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Morrisey-corrected standard deviation of SNOTEL 589 average winter temperatures for water years 1986-2021

winter MK & SS 589 (corrected)

winter_sd_mk_589_ad <- mk.test(winter_standard_dev_all_589_ad$sd_2)
print(winter_sd_mk_589_ad)
## 
##  Mann-Kendall trend test
## 
## data:  winter_standard_dev_all_589_ad$sd_2
## z = -0.25016, n = 27, p-value = 0.8025
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##             S          varS           tau 
##  -13.00000000 2301.00000000   -0.03703704
winter_sd_sens_589_ad <- sens.slope(winter_standard_dev_all_589_ad$sd_2)
print(winter_sd_sens_589_ad)
## 
##  Sen's slope
## 
## data:  winter_standard_dev_all_589_ad$sd_2
## z = -0.25016, n = 27, p-value = 0.8025
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.03055989  0.02885928
## sample estimates:
##  Sen's slope 
## -0.002906196

Spring and Fall SD NOT-CORRECTED

Spring

spring_standard_dev_all_589 <- standard_dev_589 %>%
  filter(waterDay >= 183 & waterDay <= 243) %>%
  group_by(waterYear) %>% 
  mutate(nmbr = n())

spring_standard_dev_all_589 <- spring_standard_dev_all_589 %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)

spring_standard_dev_all_589 %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1987 3.248069
1988 4.727105
1989 4.008249
1990 3.482816
1991 4.996421
1992 2.943680
1993 4.036069
1995 3.621075
1996 5.091771
1998 4.833575
1999 4.932991
2000 4.550120
2001 4.474552
2002 3.582743
2003 4.876461
2004 3.855369
2005 4.490938
2007 3.773734
2008 4.358091
2015 2.981434
2016 3.551370
2017 3.914474
2018 3.967724
2019 3.124604
2020 4.146911
2021 3.523113
2022 4.483982
ggplot(spring_standard_dev_all_589, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Non-corrected standard deviation of SNOTEL 589 average spring temperatures for water years 2005-2021

spring MK & SS for 589 (non-corrected)

spring_sd_mk_589 <- mk.test(spring_standard_dev_all_589$sd_2)
print(spring_sd_mk_589)
## 
##  Mann-Kendall trend test
## 
## data:  spring_standard_dev_all_589$sd_2
## z = -0.87557, n = 27, p-value = 0.3813
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##            S         varS          tau 
##  -43.0000000 2301.0000000   -0.1225071
spring_sd_sens_589 <- sens.slope(spring_standard_dev_all_589$sd_2)
print(spring_sd_sens_589)
## 
##  Sen's slope
## 
## data:  spring_standard_dev_all_589$sd_2
## z = -0.87557, n = 27, p-value = 0.3813
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.05905375  0.02383760
## sample estimates:
## Sen's slope 
## -0.01574448

Fall

Fall is split each water year in the middle of the season. This analysis splits the fall season between the preceding water year and the subsequent water year.

fall_standard_dev_all_589 <- standard_dev_589 %>%
  filter(waterDay >= 336 | waterDay <= 31) %>% 
  group_by(waterYear) %>% 
  mutate(nmbr = n())

fall_standard_dev_all_589 <- fall_standard_dev_all_589 %>% 
  #group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)

fall_standard_dev_all_589 %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1987 3.747760
1988 3.356086
1989 3.116951
1990 5.289319
1991 3.856660
1992 4.765725
1993 3.380582
1995 4.771082
1996 4.126856
1998 5.518169
1999 3.763392
2000 4.230918
2001 4.332217
2002 3.647165
2003 4.274210
2004 3.598510
2005 4.768890
2007 4.931895
2008 4.175625
2015 3.034173
2016 3.385118
2017 3.721081
2018 3.754777
2019 4.793445
2020 6.085248
2021 4.482687
2022 4.992026
ggplot(fall_standard_dev_all_589, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Non-corrected standard deviation of SNOTEL 589 average fall temperatures for water years 2005-2021. Note that the season is split by the water year.

fall MK & SS for 589 (non-corrected)

fall_sd_mk_589 <- mk.test(fall_standard_dev_all_589$sd_2)
print(fall_sd_mk_589)
## 
##  Mann-Kendall trend test
## 
## data:  fall_standard_dev_all_589$sd_2
## z = 1.2925, n = 27, p-value = 0.1962
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##            S         varS          tau 
##   63.0000000 2301.0000000    0.1794872
fall_sd_sens_589 <- sens.slope(fall_standard_dev_all_589$sd_2)
print(fall_sd_sens_589)
## 
##  Sen's slope
## 
## data:  fall_standard_dev_all_589$sd_2
## z = 1.2925, n = 27, p-value = 0.1962
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.02307509  0.06533448
## sample estimates:
## Sen's slope 
##   0.0227832

Spring and Fall SD CORRECTED

Spring

spring_standard_dev_all_589_ad <- standard_dev_589_ad %>% 
  filter(waterDay >= 183 & waterDay <= 243) %>%
  group_by(waterYear) %>% 
  mutate(nmbr = n())
spring_standard_dev_all_589_ad <- spring_standard_dev_all_589_ad %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)
spring_standard_dev_all_589_ad %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1987 2.997408
1988 4.369182
1989 3.663950
1990 3.194680
1991 4.633186
1992 2.695508
1993 3.719219
1995 3.361355
1996 4.675973
1998 4.457077
1999 4.573702
2000 4.156241
2001 4.108794
2002 3.253946
2003 4.477306
2004 3.526146
2005 4.111315
2007 3.773451
2008 4.358293
2015 2.981240
2016 3.551011
2017 3.914579
2018 3.967775
2019 3.124771
2020 4.146682
2021 3.522914
2022 4.484158
ggplot(spring_standard_dev_all_589_ad, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Morrisey-corrected standard deviation of SNOTEL 589 average spring temperatures for water years 1986-2021

spring MK & SS 589 (corrected)

spring_sd_mk_589_ad <- mk.test(spring_standard_dev_all_589_ad$sd_2)
print(spring_sd_mk_589_ad)
## 
##  Mann-Kendall trend test
## 
## data:  spring_standard_dev_all_589_ad$sd_2
## z = 0.041694, n = 27, p-value = 0.9667
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##            S         varS          tau 
## 3.000000e+00 2.301000e+03 8.547009e-03
spring_sd_sens_589_ad <- sens.slope(spring_standard_dev_all_589_ad$sd_2)
print(spring_sd_sens_589_ad)
## 
##  Sen's slope
## 
## data:  spring_standard_dev_all_589_ad$sd_2
## z = 0.041694, n = 27, p-value = 0.9667
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.03308066  0.03999436
## sample estimates:
##  Sen's slope 
## 0.0006301379

Fall

fall_standard_dev_all_589_ad <- standard_dev_589_ad %>% 
  filter(waterDay >= 336 | waterDay <= 31) %>%
  group_by(waterYear) %>% 
  mutate(nmbr = n())
fall_standard_dev_all_589_ad <- fall_standard_dev_all_589_ad %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)
fall_standard_dev_all_589_ad %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1987 3.483614
1988 3.051714
1989 2.818131
1990 4.852959
1991 3.534669
1992 4.412119
1993 3.078967
1995 4.339944
1996 3.776052
1998 5.068020
1999 3.444997
2000 3.852375
2001 3.948416
2002 3.329209
2003 3.912139
2004 3.274666
2005 4.182220
2007 4.931805
2008 4.175467
2015 3.035032
2016 3.384190
2017 3.721673
2018 3.756016
2019 4.793174
2020 6.086172
2021 4.483404
2022 4.993219
ggplot(fall_standard_dev_all_589_ad, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Morrisey-corrected standard deviation of SNOTEL 589 average fall temperatures for water years 1986-2021. Note that the fall season is split by the water year.

fall MK & SS 589 (corrected)

fall_sd_mk_589_ad <- mk.test(fall_standard_dev_all_589_ad$sd_2)
print(fall_sd_mk_589_ad)
## 
##  Mann-Kendall trend test
## 
## data:  fall_standard_dev_all_589_ad$sd_2
## z = 1.8345, n = 27, p-value = 0.06658
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##            S         varS          tau 
##   89.0000000 2301.0000000    0.2535613
fall_sd_sens_589_ad <- sens.slope(fall_standard_dev_all_589_ad$sd_2)
print(fall_sd_sens_589_ad)
## 
##  Sen's slope
## 
## data:  fall_standard_dev_all_589_ad$sd_2
## z = 1.8345, n = 27, p-value = 0.06658
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.003376252  0.075367038
## sample estimates:
## Sen's slope 
##  0.03999156

Middle Creek 624

Morrisey 6/26/2006

snotel_624 <- SNOTEL_san_juan_Area %>% 
  filter(site_id == "624")
#str(snotel_624) # check the date, usually a character.  

snotel_624$Date <- as.Date(snotel_624$date) #change date from character to date format, capitalize to work with Water year functon from NWIS.

#THIS WILL CHANGE FOR EACH STATION
snotel_624_clean <- snotel_624 %>% # filter for the timeframe
  filter(Date >= "1979-10-01" & Date <= "2022-09-30") %>%
  #filter(temperature_mean >= -30 & temperature_mean <= 20) %>% # removing outliers   
  addWaterYear() %>% 
  mutate(daymonth = format(as.Date(Date), "%d-%m")) %>% 
  na.omit()

#adding water day using difftime (SUPER COOL. example from [this](https://stackoverflow.com/questions/48123049/create-day-index-based-on-water-year))

snotel_624_clean <- snotel_624_clean %>% 
  group_by(waterYear)%>% 
  mutate(waterDay = (as.integer(difftime(Date, ymd(paste0(waterYear - 1 ,'-09-30')), units = "days"))))
# Check for outliers

ggplot(snotel_624_clean, aes(x = Date, y = temperature_mean)) +
  geom_point() + #lwd = 2) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('Daily temperature (°C)') + 
  xlab('Date')

snotel_624_clean <- snotel_624_clean %>% 
  mutate(temp_diff = abs(temperature_min - temperature_max)) %>% 
  filter(temperature_mean > -40) %>% 
  filter(temperature_mean < 25)
ggplot(snotel_624_clean, aes(x = Date, y = temp_diff)) + 
  geom_point() + #lwd = 2) +
  theme_few() +
  #geom_smooth(method = "lm", se=FALSE) +
  ylab('Daily temperature varience (°C)') + 
  xlab('Date')

Per Steven’s advice: :If there are more than 15 missing days, then…remove that year”

# filtering for temperature anomalies
snotel_624_cull_count <- snotel_624_clean %>% 
  filter(temperature_min > -40) %>% 
  count(waterYear)

snotel_624_cull_count
## # A tibble: 43 x 2
## # Groups:   waterYear [43]
##    waterYear     n
##        <dbl> <int>
##  1      1980    59
##  2      1981   354
##  3      1982     1
##  4      1983   312
##  5      1984   360
##  6      1985   362
##  7      1986   364
##  8      1987   360
##  9      1988   340
## 10      1989   363
## # ... with 33 more rows
# filtering for too few observations in a year
snotel_624_cull_count_days <- snotel_624_clean %>% 
  group_by(waterYear) %>% 
  count(waterYear) %>% 
  filter(n < 350)

snotel_624_cull_count_days
## # A tibble: 9 x 2
## # Groups:   waterYear [9]
##   waterYear     n
##       <dbl> <int>
## 1      1980    59
## 2      1982     1
## 3      1983   312
## 4      1988   340
## 5      1991   338
## 6      1993   330
## 7      1994   330
## 8      2021   338
## 9      2022   348

1980, 1982, 1983, 1988, 1991, 1993, 1994, 2021, 2022 need to be culled.

snotel_624_clean_culled <- snotel_624_clean %>% 
  filter(waterYear != "1980" & waterYear != "1981" & waterYear != "1982" & waterYear != "1983" & waterYear != "1988" & waterYear != "1991" & waterYear != "1993" & waterYear != "1994" & waterYear != "2021" & waterYear != "2022")# & waterYear != "2014") #%>% 
  #filter(temperature_mean > -49)

ggplot(snotel_624_clean_culled, aes(x = Date, y = temp_diff)) + 
  geom_point() + #lwd = 2) +
  theme_few() +
  #geom_smooth(method = "lm", se=FALSE) +
  ylab('Daily temperature varience (°C)') + 
  xlab('Date')

ggplot(snotel_624_clean_culled, aes(x = Date, y = temperature_mean)) + 
  geom_point() + #lwd = 2) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('Daily temperature (°C)') + 
  xlab('Date')

temp_624_xts <- xts(snotel_624_clean_culled$temperature_mean, order.by = snotel_624_clean_culled$Date)

dygraph(temp_624_xts) %>%
  dyAxis("y", label = "Daily mean temperature (°C)") 
snotel_624_clean_culled <- snotel_624_clean_culled %>% 
  filter(temperature_mean < 20)

temp_624_xts <- xts(snotel_624_clean_culled$temperature_mean, order.by = snotel_624_clean_culled$Date)

dygraph(temp_624_xts) %>%
  dyAxis("y", label = "Daily mean temperature (°C)") 

Middle Creek 624 Morrisey 6/26/2006

snotel_624_adjusted <- snotel_624_clean_culled %>%
  mutate(temp_ad = if_else(Date < "2006-06-26", ((5.3*10^(-7))*(temperature_mean^(4))+(3.72*10^(-5))*(temperature_mean^(3))-(2.16*10^(-3))*(temperature_mean^(2))-(7.32*10^(-2))*(temperature_mean)+1.37)+temperature_mean, temperature_mean))

Non-corrected

624 Detrended

#using the clean culled df:

#average water year temperature

yearly_wy_aver_624 <- snotel_624_adjusted %>% 
  group_by(waterYear) %>% 
  mutate(aver_ann_temp = mean(temperature_mean))

#Average temperature by day for all water years:

daily_wy_aver_624 <- yearly_wy_aver_624 %>% 
  group_by(daymonth) %>% 
  mutate(aver_day_temp = mean(aver_ann_temp))

#average mean temperature by day for the period of record:

daily_wy_aver_624 <- daily_wy_aver_624 %>% 
  group_by(daymonth) %>% 
  mutate(all_ave_temp = mean(daily_wy_aver_624$aver_day_temp))

# try to show all years as means. 
daily_wy_aver2_624 <-daily_wy_aver_624 %>% 
  group_by(waterDay) %>%
  mutate(date_temp = mean(temperature_mean))
  

daily_wy_aver2_624$date_temp <- signif(daily_wy_aver2_624$date_temp,3) #reduce the sig figs


ggplot(daily_wy_aver2_624, aes(x = waterDay, y = date_temp))+
  geom_line(size= 0.7) +
  theme_few() +
  ylab('Average Daily temperature (°C)') + 
  xlab('Day of water year')

624 SD

standard_dev_624 <- daily_wy_aver_624 %>% 
  group_by(waterYear) %>% 
  mutate(residual = (all_ave_temp-aver_ann_temp)+temperature_mean-aver_day_temp) %>% 
  mutate(deviation = abs(residual-lag(residual)))

standard_dev_all_624 <- standard_dev_624 %>% 
  group_by(waterYear) %>% 
  mutate(nmbr = n())

standard_dev_all_624 <- standard_dev_all_624 %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)

standard_dev_all_624 %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1984 8.239005
1985 8.207104
1986 7.191318
1987 7.871848
1989 8.454185
1990 8.200220
1992 6.438238
1995 7.565327
1996 7.835558
1997 7.996219
1998 8.415139
1999 7.174609
2000 7.839800
2001 8.355597
2002 8.492066
2003 8.150297
2004 7.912597
2005 7.915951
2006 7.936724
2007 7.640492
2008 8.021623
2009 7.171130
2010 8.259271
2011 7.932618
2012 7.791063
2013 8.259320
2014 7.372950
2015 6.806548
2016 7.548199
2017 7.108731
2018 7.036935
2019 7.675916
2020 7.741703
ggplot(standard_dev_all_624, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Non-corrected standard deviation of SNOTEL 624 average temperatures for water years 2005-2021

MK & SS for 624 (non-corrected)

sd_mk_624 <- mk.test(standard_dev_all_624$sd_2)
print(sd_mk_624)
## 
##  Mann-Kendall trend test
## 
## data:  standard_dev_all_624$sd_2
## z = -1.9678, n = 33, p-value = 0.04909
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##            S         varS          tau 
## -128.0000000 4165.3333333   -0.2424242
sd_sens_624 <- sens.slope(standard_dev_all_624$sd_2)
print(sd_sens_624)
## 
##  Sen's slope
## 
## data:  standard_dev_all_624$sd_2
## z = -1.9678, n = 33, p-value = 0.04909
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.0333661824 -0.0003479011
## sample estimates:
## Sen's slope 
## -0.01662145

Corrected

624 Detrended (corrected)

#using the clean culled df:
#average water year temperature
yearly_wy_aver_624_ad <- snotel_624_adjusted %>% 
  group_by(waterYear) %>% 
  mutate(aver_ann_temp_ad = mean(temp_ad))
#Average temperature by day for all water years:
daily_wy_aver_624_ad <- yearly_wy_aver_624_ad %>% 
  group_by(daymonth) %>% 
  mutate(aver_day_temp_ad = mean(aver_ann_temp_ad))
#average mean temperature by day for the period of record:
daily_wy_aver_624_ad <- daily_wy_aver_624_ad %>% 
  group_by(daymonth) %>% 
  mutate(all_ave_temp_ad = mean(daily_wy_aver_624_ad$aver_day_temp_ad))
# try to show all years as means. 
daily_wy_aver2_624_ad <-daily_wy_aver_624_ad %>% 
  group_by(waterDay) %>%
  mutate(date_temp_ad = mean(temp_ad))
  
daily_wy_aver2_624_ad$date_temp_ad <- signif(daily_wy_aver2_624_ad$date_temp_ad,3) #reduce the sig figs
ggplot(daily_wy_aver2_624_ad, aes(x = waterDay, y = date_temp_ad))+
  geom_line(size= 0.7) +
  theme_few() +
  ylab('Average Daily temperature (°C)') + 
  xlab('Day of water year')

624 SS (corrected)

standard_dev_624_ad <- daily_wy_aver_624_ad %>% 
  group_by(waterYear) %>% 
  #filter(waterYear >= 1987 & waterYear <= 2021) %>% 
  mutate(residual = (all_ave_temp_ad-aver_ann_temp_ad)+temp_ad-aver_day_temp_ad) %>% 
  mutate(deviation = abs(residual-lag(residual)))
standard_dev_all_624_ad <- standard_dev_624_ad %>% 
  group_by(waterYear) %>% 
  mutate(nmbr = n())
standard_dev_all_624_ad <- standard_dev_all_624_ad %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)
standard_dev_all_624_ad %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1984 7.738801
1985 7.713059
1986 6.725366
1987 7.374899
1989 7.942209
1990 7.687289
1992 6.080980
1995 7.080976
1996 7.336792
1997 7.519955
1998 7.885653
1999 6.718142
2000 7.329553
2001 7.833709
2002 7.944757
2003 7.617514
2004 7.442397
2005 7.390605
2006 7.304030
2007 7.639661
2008 8.021493
2009 7.170919
2010 8.259153
2011 7.932368
2012 7.790490
2013 8.259010
2014 7.372461
2015 6.806595
2016 7.547948
2017 7.107845
2018 7.036548
2019 7.675791
2020 7.741347
ggplot(standard_dev_all_624_ad, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Morrisey-corrected standard deviation of SNOTEL 624 average temperatures for water years 1986-2021

MK & SS 624 (corrected)

sd_mk_624_ad <- mk.test(standard_dev_all_624_ad$sd_2)
print(sd_mk_624_ad)
## 
##  Mann-Kendall trend test
## 
## data:  standard_dev_all_624_ad$sd_2
## z = 0.35637, n = 33, p-value = 0.7216
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##            S         varS          tau 
## 2.400000e+01 4.165333e+03 4.545455e-02
sd_sens_624_ad <- sens.slope(standard_dev_all_624_ad$sd_2)
print(sd_sens_624_ad)
## 
##  Sen's slope
## 
## data:  standard_dev_all_624_ad$sd_2
## z = 0.35637, n = 33, p-value = 0.7216
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.01304163  0.02223675
## sample estimates:
## Sen's slope 
## 0.003307866

Summer and Winter SD NOT-CORRECTED

Summer

summer_standard_dev_all_624 <- standard_dev_624 %>%
  filter(waterDay >= 244 & waterDay <= 335) %>%
  group_by(waterYear) %>% 
  mutate(nmbr = n())

summer_standard_dev_all_624 <- summer_standard_dev_all_624 %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)

summer_standard_dev_all_624 %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1984 2.371017
1985 1.990557
1986 2.214926
1987 2.127623
1989 3.126720
1990 2.993512
1992 2.774353
1995 3.067086
1996 1.948609
1997 2.086138
1998 2.740390
1999 2.498199
2000 1.663313
2001 2.287905
2002 1.934590
2003 2.763802
2004 2.268487
2005 2.997242
2006 1.968704
2007 2.171153
2008 2.014715
2009 2.529582
2010 2.116445
2011 1.825302
2012 1.620883
2013 1.738808
2014 1.728048
2015 2.122215
2016 2.479053
2017 1.908542
2018 1.727760
2019 2.334135
2020 2.281772
ggplot(summer_standard_dev_all_624, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Non-corrected standard deviation of SNOTEL 624 average summer temperatures for water years 2005-2021

summer MK & SS for 624 (non-corrected)

summer_sd_mk_624 <- mk.test(summer_standard_dev_all_624$sd_2)
print(summer_sd_mk_624)
## 
##  Mann-Kendall trend test
## 
## data:  summer_standard_dev_all_624$sd_2
## z = -2.2157, n = 33, p-value = 0.02671
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##            S         varS          tau 
## -144.0000000 4165.3333333   -0.2727273
summer_sd_sens_624 <- sens.slope(summer_standard_dev_all_624$sd_2)
print(summer_sd_sens_624)
## 
##  Sen's slope
## 
## data:  summer_standard_dev_all_624$sd_2
## z = -2.2157, n = 33, p-value = 0.02671
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.032758709 -0.001736526
## sample estimates:
## Sen's slope 
## -0.01764104

Winter

winter_standard_dev_all_624 <- standard_dev_624 %>%
  filter(waterDay >= 32 & waterDay <= 182) %>%
  group_by(waterYear) %>% 
  mutate(nmbr = n())

winter_standard_dev_all_624 <- winter_standard_dev_all_624 %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)

winter_standard_dev_all_624 %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1984 4.880677
1985 4.967858
1986 4.529985
1987 4.210844
1989 5.844668
1990 5.265678
1992 4.334760
1995 4.484677
1996 4.859324
1997 5.244493
1998 4.464080
1999 4.568526
2000 4.981760
2001 4.150395
2002 5.034307
2003 4.334739
2004 5.397423
2005 4.048105
2006 4.873371
2007 5.229029
2008 5.643945
2009 4.491409
2010 4.672503
2011 5.153151
2012 4.528698
2013 5.749451
2014 4.130044
2015 4.667844
2016 4.917047
2017 4.988580
2018 4.254723
2019 4.126243
2020 4.441848
ggplot(winter_standard_dev_all_624, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Non-corrected standard deviation of SNOTEL 624 average winter temperatures for water years 2005-2021

winter MK & SS for 624 (non-corrected)

winter_sd_mk_624 <- mk.test(winter_standard_dev_all_624$sd_2)
print(winter_sd_mk_624)
## 
##  Mann-Kendall trend test
## 
## data:  winter_standard_dev_all_624$sd_2
## z = -0.72824, n = 33, p-value = 0.4665
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##             S          varS           tau 
##  -48.00000000 4165.33333333   -0.09090909
winter_sd_sens_624 <- sens.slope(winter_standard_dev_all_624$sd_2)
print(winter_sd_sens_624)
## 
##  Sen's slope
## 
## data:  winter_standard_dev_all_624$sd_2
## z = -0.72824, n = 33, p-value = 0.4665
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.02629849  0.01320480
## sample estimates:
##  Sen's slope 
## -0.005315308

Summer and Winter SD CORRECTED

Summer

summer_standard_dev_all_624_ad <- standard_dev_624_ad %>% 
  filter(waterDay >= 244 & waterDay <= 335) %>%
  group_by(waterYear) %>% 
  mutate(nmbr = n())
summer_standard_dev_all_624_ad <- summer_standard_dev_all_624_ad %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)
summer_standard_dev_all_624_ad %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1984 2.145259
1985 1.790887
1986 1.997447
1987 1.914709
1989 2.815434
1990 2.692193
1992 2.529956
1995 2.767172
1996 1.750562
1997 1.882650
1998 2.473916
1999 2.260191
2000 1.490901
2001 2.064709
2002 1.736917
2003 2.482808
2004 2.042300
2005 2.699490
2006 1.867032
2007 2.171811
2008 2.013205
2009 2.528350
2010 2.116246
2011 1.824621
2012 1.619325
2013 1.738330
2014 1.727368
2015 2.123161
2016 2.476465
2017 1.906976
2018 1.725631
2019 2.336097
2020 2.284118
ggplot(summer_standard_dev_all_624_ad, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Morrisey-corrected standard deviation of SNOTEL 624 average summer temperatures for water years 1986-2021

summer MK & SS 624 (corrected)

summer_sd_mk_624_ad <- mk.test(summer_standard_dev_all_624_ad$sd_2)
print(summer_sd_mk_624_ad)
## 
##  Mann-Kendall trend test
## 
## data:  summer_standard_dev_all_624_ad$sd_2
## z = -1.1311, n = 33, p-value = 0.258
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##            S         varS          tau 
##  -74.0000000 4165.3333333   -0.1401515
summer_sd_sens_624_ad <- sens.slope(summer_standard_dev_all_624_ad$sd_2)
print(summer_sd_sens_624_ad)
## 
##  Sen's slope
## 
## data:  summer_standard_dev_all_624_ad$sd_2
## z = -1.1311, n = 33, p-value = 0.258
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.02093851  0.00744829
## sample estimates:
## Sen's slope 
## -0.00746448

Winter

winter_standard_dev_all_624_ad <- standard_dev_624_ad %>% 
  filter(waterDay >= 32 & waterDay <= 182) %>%
  group_by(waterYear) %>% 
  mutate(nmbr = n())
winter_standard_dev_all_624_ad <- winter_standard_dev_all_624_ad %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)
winter_standard_dev_all_624_ad %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1984 4.762851
1985 4.874175
1986 4.380676
1987 4.097807
1989 5.676966
1990 5.119591
1992 4.197936
1995 4.351814
1996 4.723854
1997 5.101032
1998 4.342229
1999 4.427507
2000 4.822826
2001 4.059517
2002 4.873722
2003 4.214189
2004 5.243926
2005 3.944212
2006 4.732233
2007 5.226846
2008 5.644781
2009 4.491025
2010 4.672103
2011 5.153036
2012 4.528179
2013 5.749052
2014 4.129798
2015 4.667792
2016 4.916706
2017 4.986515
2018 4.254240
2019 4.126244
2020 4.441082
ggplot(winter_standard_dev_all_624_ad, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Morrisey-corrected standard deviation of SNOTEL 624 average winter temperatures for water years 1986-2021

winter MK & SS 624 (corrected)

winter_sd_mk_624_ad <- mk.test(winter_standard_dev_all_624_ad$sd_2)
print(winter_sd_mk_624_ad)
## 
##  Mann-Kendall trend test
## 
## data:  winter_standard_dev_all_624_ad$sd_2
## z = -0.046483, n = 33, p-value = 0.9629
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##             S          varS           tau 
## -4.000000e+00  4.165333e+03 -7.575758e-03
winter_sd_sens_624_ad <- sens.slope(winter_standard_dev_all_624_ad$sd_2)
print(winter_sd_sens_624_ad)
## 
##  Sen's slope
## 
## data:  winter_standard_dev_all_624_ad$sd_2
## z = -0.046483, n = 33, p-value = 0.9629
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.01984730  0.02049392
## sample estimates:
##   Sen's slope 
## -0.0007865011

Spring and Fall SD NOT-CORRECTED

Spring

spring_standard_dev_all_624 <- standard_dev_624 %>%
  filter(waterDay >= 183 & waterDay <= 243) %>%
  group_by(waterYear) %>% 
  mutate(nmbr = n())

spring_standard_dev_all_624 <- spring_standard_dev_all_624 %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)

spring_standard_dev_all_624 %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1984 6.094849
1985 3.332133
1986 3.938140
1987 3.436259
1989 4.328637
1990 2.937711
1992 2.854650
1995 4.055689
1996 5.248533
1997 4.865094
1998 5.145796
1999 4.964205
2000 4.694307
2001 4.530730
2002 3.246274
2003 4.784336
2004 4.016391
2005 4.673105
2006 3.605193
2007 3.526874
2008 4.367009
2009 4.828635
2010 4.730744
2011 4.235905
2012 3.906247
2013 4.496269
2014 4.905107
2015 2.968518
2016 3.748216
2017 4.191740
2018 4.233644
2019 3.342097
2020 4.122583
ggplot(spring_standard_dev_all_624, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Non-corrected standard deviation of SNOTEL 624 average spring temperatures for water years 2005-2021

spring MK & SS for 624 (non-corrected)

spring_sd_mk_624 <- mk.test(spring_standard_dev_all_624$sd_2)
print(spring_sd_mk_624)
## 
##  Mann-Kendall trend test
## 
## data:  spring_standard_dev_all_624$sd_2
## z = -0.63527, n = 33, p-value = 0.5253
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##             S          varS           tau 
##  -42.00000000 4165.33333333   -0.07954545
spring_sd_sens_624 <- sens.slope(spring_standard_dev_all_624$sd_2)
print(spring_sd_sens_624)
## 
##  Sen's slope
## 
## data:  spring_standard_dev_all_624$sd_2
## z = -0.63527, n = 33, p-value = 0.5253
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.04494206  0.02394765
## sample estimates:
## Sen's slope 
## -0.01350826

Fall

Fall is split each water year in the middle of the season. This analysis splits the fall season between the preceding water year and the subsequent water year.

fall_standard_dev_all_624 <- standard_dev_624 %>%
  filter(waterDay >= 336 | waterDay <= 31) %>% 
  group_by(waterYear) %>% 
  mutate(nmbr = n())

fall_standard_dev_all_624 <- fall_standard_dev_all_624 %>% 
  #group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)

fall_standard_dev_all_624 %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1984 3.178893
1985 5.385749
1986 3.109025
1987 3.640681
1989 2.776282
1990 5.306271
1992 4.075518
1995 4.680720
1996 3.630869
1997 5.513650
1998 5.583165
1999 3.853876
2000 3.933586
2001 4.279291
2002 3.195135
2003 4.422246
2004 3.497764
2005 4.637283
2006 3.430055
2007 4.475269
2008 3.457202
2009 3.587696
2010 5.846136
2011 3.813707
2012 4.216897
2013 4.055775
2014 5.274171
2015 2.900719
2016 3.403076
2017 3.123169
2018 3.472161
2019 4.752909
2020 5.946142
ggplot(fall_standard_dev_all_624, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Non-corrected standard deviation of SNOTEL 624 average fall temperatures for water years 2005-2021. Note that the season is split by the water year.

fall MK & SS for 624 (non-corrected)

fall_sd_mk_624 <- mk.test(fall_standard_dev_all_624$sd_2)
print(fall_sd_mk_624)
## 
##  Mann-Kendall trend test
## 
## data:  fall_standard_dev_all_624$sd_2
## z = 0.17044, n = 33, p-value = 0.8647
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##            S         varS          tau 
## 1.200000e+01 4.165333e+03 2.272727e-02
fall_sd_sens_624 <- sens.slope(fall_standard_dev_all_624$sd_2)
print(fall_sd_sens_624)
## 
##  Sen's slope
## 
## data:  fall_standard_dev_all_624$sd_2
## z = 0.17044, n = 33, p-value = 0.8647
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.03385467  0.04312228
## sample estimates:
## Sen's slope 
##  0.00629304

Spring and Fall SD CORRECTED

Spring

spring_standard_dev_all_624_ad <- standard_dev_624_ad %>% 
  filter(waterDay >= 183 & waterDay <= 243) %>%
  group_by(waterYear) %>% 
  mutate(nmbr = n())
spring_standard_dev_all_624_ad <- spring_standard_dev_all_624_ad %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)
spring_standard_dev_all_624_ad %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1984 5.670201
1985 3.078286
1986 3.660458
1987 3.193866
1989 3.994326
1990 2.704159
1992 2.677971
1995 3.801687
1996 4.854694
1997 4.557747
1998 4.802340
1999 4.665375
2000 4.323615
2001 4.197237
2002 2.976267
2003 4.447578
2004 3.712206
2005 4.314239
2006 3.322723
2007 3.526643
2008 4.367000
2009 4.828683
2010 4.730817
2011 4.236154
2012 3.905815
2013 4.496149
2014 4.905053
2015 2.968256
2016 3.747942
2017 4.192232
2018 4.233889
2019 3.342258
2020 4.122250
ggplot(spring_standard_dev_all_624_ad, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Morrisey-corrected standard deviation of SNOTEL 624 average spring temperatures for water years 1986-2021

spring MK & SS 624 (corrected)

spring_sd_mk_624_ad <- mk.test(spring_standard_dev_all_624_ad$sd_2)
print(spring_sd_mk_624_ad)
## 
##  Mann-Kendall trend test
## 
## data:  spring_standard_dev_all_624_ad$sd_2
## z = 0.26341, n = 33, p-value = 0.7922
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##            S         varS          tau 
## 1.800000e+01 4.165333e+03 3.409091e-02
spring_sd_sens_624_ad <- sens.slope(spring_standard_dev_all_624_ad$sd_2)
print(spring_sd_sens_624_ad)
## 
##  Sen's slope
## 
## data:  spring_standard_dev_all_624_ad$sd_2
## z = 0.26341, n = 33, p-value = 0.7922
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.02586308  0.03858128
## sample estimates:
## Sen's slope 
## 0.004712936

Fall

fall_standard_dev_all_624_ad <- standard_dev_624_ad %>% 
  filter(waterDay >= 336 | waterDay <= 31) %>%
  group_by(waterYear) %>% 
  mutate(nmbr = n())
fall_standard_dev_all_624_ad <- fall_standard_dev_all_624_ad %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)
fall_standard_dev_all_624_ad %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1984 2.899068
1985 5.027550
1986 2.861429
1987 3.369373
1989 2.527128
1990 4.884754
1992 3.827995
1995 4.300191
1996 3.350363
1997 5.132235
1998 5.179087
1999 3.557878
2000 3.605698
2001 3.942401
2002 2.926282
2003 4.086276
2004 3.204925
2005 4.274516
2006 3.081478
2007 4.473790
2008 3.457330
2009 3.589545
2010 5.847116
2011 3.813509
2012 4.216309
2013 4.054870
2014 5.271970
2015 2.901361
2016 3.403862
2017 3.121126
2018 3.471908
2019 4.751137
2020 5.945741
ggplot(fall_standard_dev_all_624_ad, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Morrisey-corrected standard deviation of SNOTEL 624 average fall temperatures for water years 1986-2021. Note that the fall season is split by the water year.

fall MK & SS 624 (corrected)

fall_sd_mk_624_ad <- mk.test(fall_standard_dev_all_624_ad$sd_2)
print(fall_sd_mk_624_ad)
## 
##  Mann-Kendall trend test
## 
## data:  fall_standard_dev_all_624_ad$sd_2
## z = 1.1001, n = 33, p-value = 0.2713
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##            S         varS          tau 
##   72.0000000 4165.3333333    0.1363636
fall_sd_sens_624_ad <- sens.slope(fall_standard_dev_all_624_ad$sd_2)
print(fall_sd_sens_624_ad)
## 
##  Sen's slope
## 
## data:  fall_standard_dev_all_624_ad$sd_2
## z = 1.1001, n = 33, p-value = 0.2713
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.01854594  0.05660956
## sample estimates:
## Sen's slope 
##  0.01884068

Molas Lake 632

NSCE-Morrisey, Bias-Original 10/2/2003

snotel_632 <- SNOTEL_san_juan_Area %>% 
  filter(site_id == "632")
#str(snotel_632) # check the date, usually a character.  

snotel_632$Date <- as.Date(snotel_632$date) #change date from character to date format, capitalize to work with Water year functon from NWIS.

#THIS WILL CHANGE FOR EACH STATION
snotel_632_clean <- snotel_632 %>% # filter for the timeframe
  filter(Date >= "1979-10-01" & Date <= "2022-09-30") %>%
  #filter(temperature_mean >= -30 & temperature_mean <= 20) %>% # removing outliers   
  addWaterYear() %>% 
  mutate(daymonth = format(as.Date(Date), "%d-%m")) %>% 
  na.omit()

#adding water day using difftime (SUPER COOL. example from [this](https://stackoverflow.com/questions/48123049/create-day-index-based-on-water-year))

snotel_632_clean <- snotel_632_clean %>% 
  group_by(waterYear)%>% 
  mutate(waterDay = (as.integer(difftime(Date, ymd(paste0(waterYear - 1 ,'-09-30')), units = "days"))))
# Check for outliers

ggplot(snotel_632_clean, aes(x = Date, y = temperature_mean)) +
  geom_point() + #lwd = 2) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('Daily temperature (°C)') + 
  xlab('Date')

snotel_632_clean <- snotel_632_clean %>% 
  mutate(temp_diff = abs(temperature_min - temperature_max)) %>% 
  #filter(temperature_mean > -40) %>% 
  filter(temperature_mean < 25)
ggplot(snotel_632_clean, aes(x = Date, y = temp_diff)) + 
  geom_point() + #lwd = 2) +
  theme_few() +
  #geom_smooth(method = "lm", se=FALSE) +
  ylab('Daily temperature varience (°C)') + 
  xlab('Date')

Per Steven’s advice: :If there are more than 15 missing days, then…remove that year”

# filtering for temperature anomalies
snotel_632_cull_count <- snotel_632_clean %>% 
  filter(temperature_min > -40) %>% 
  count(waterYear)

snotel_632_cull_count
## # A tibble: 37 x 2
## # Groups:   waterYear [37]
##    waterYear     n
##        <dbl> <int>
##  1      1986    54
##  2      1987   355
##  3      1988   362
##  4      1989   364
##  5      1990   365
##  6      1991   365
##  7      1992   366
##  8      1993   303
##  9      1994   294
## 10      1995   361
## # ... with 27 more rows
# filtering for too few observations in a year
snotel_632_cull_count_days <- snotel_632_clean %>% 
  group_by(waterYear) %>% 
  count(waterYear) %>% 
  filter(n < 350)

snotel_632_cull_count_days
## # A tibble: 6 x 2
## # Groups:   waterYear [6]
##   waterYear     n
##       <dbl> <int>
## 1      1986    54
## 2      1993   303
## 3      1994   295
## 4      2005   344
## 5      2006   304
## 6      2013   248

1986, 1993, 1994, 2005, 2006, 2013 need to be culled.

snotel_632_clean_culled <- snotel_632_clean %>% 
  filter(waterYear != "1986" & waterYear != "1993" & waterYear != "1994" & waterYear != "2005" & waterYear != "2006" & waterYear != "2013")# & waterYear != "1993" & waterYear != "1994" & waterYear != "2021" & waterYear != "2022") & waterYear != "2014") #%>% 
  #filter(temperature_mean > -49)

ggplot(snotel_632_clean_culled, aes(x = Date, y = temp_diff)) + 
  geom_point() + #lwd = 2) +
  theme_few() +
  #geom_smooth(method = "lm", se=FALSE) +
  ylab('Daily temperature varience (°C)') + 
  xlab('Date')

ggplot(snotel_632_clean_culled, aes(x = Date, y = temperature_mean)) + 
  geom_point() + #lwd = 2) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('Daily temperature (°C)') + 
  xlab('Date')

temp_632_xts <- xts(snotel_632_clean_culled$temperature_mean, order.by = snotel_632_clean_culled$Date)

dygraph(temp_632_xts) %>%
  dyAxis("y", label = "Daily mean temperature (°C)") 
snotel_632_clean_culled <- snotel_632_clean_culled %>% 
  filter(temperature_mean < 20)

temp_632_xts <- xts(snotel_632_clean_culled$temperature_mean, order.by = snotel_632_clean_culled$Date)

dygraph(temp_632_xts) %>%
  dyAxis("y", label = "Daily mean temperature (°C)") 

Molas Lake 632

NSCE-Morrisey, Bias-Original 10/2/2003

snotel_632_adjusted <- snotel_632_clean_culled %>%
  mutate(temp_ad = if_else(Date < "2003-10-02", ((5.3*10^(-7))*(temperature_mean^(4))+(3.72*10^(-5))*(temperature_mean^(3))-(2.16*10^(-3))*(temperature_mean^(2))-(7.32*10^(-2))*(temperature_mean)+1.37)+temperature_mean, temperature_mean))

Non-corrected

632 Detrended

#using the clean culled df:

#average water year temperature

yearly_wy_aver_632 <- snotel_632_adjusted %>% 
  group_by(waterYear) %>% 
  mutate(aver_ann_temp = mean(temperature_mean))

#Average temperature by day for all water years:

daily_wy_aver_632 <- yearly_wy_aver_632 %>% 
  group_by(daymonth) %>% 
  mutate(aver_day_temp = mean(aver_ann_temp))

#average mean temperature by day for the period of record:

daily_wy_aver_632 <- daily_wy_aver_632 %>% 
  group_by(daymonth) %>% 
  mutate(all_ave_temp = mean(daily_wy_aver_632$aver_day_temp))

# try to show all years as means. 
daily_wy_aver2_632 <-daily_wy_aver_632 %>% 
  group_by(waterDay) %>%
  mutate(date_temp = mean(temperature_mean))
  

daily_wy_aver2_632$date_temp <- signif(daily_wy_aver2_632$date_temp,3) #reduce the sig figs


ggplot(daily_wy_aver2_632, aes(x = waterDay, y = date_temp))+
  geom_line(size= 0.7) +
  theme_few() +
  ylab('Average Daily temperature (°C)') + 
  xlab('Day of water year')

632 SD

standard_dev_632 <- daily_wy_aver_632 %>% 
  group_by(waterYear) %>% 
  mutate(residual = (all_ave_temp-aver_ann_temp)+temperature_mean-aver_day_temp) %>% 
  mutate(deviation = abs(residual-lag(residual)))

standard_dev_all_632 <- standard_dev_632 %>% 
  group_by(waterYear) %>% 
  mutate(nmbr = n())

standard_dev_all_632 <- standard_dev_all_632 %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)

standard_dev_all_632 %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1987 7.613234
1988 8.191410
1989 8.166070
1990 7.646926
1991 7.969691
1992 7.156808
1995 7.489888
1996 7.655841
1997 7.698012
1998 8.157837
1999 6.885991
2000 7.657554
2001 6.788385
2002 8.254532
2003 7.907020
2004 7.308264
2007 7.607147
2008 7.964946
2009 6.957483
2010 7.983696
2011 7.701623
2012 7.490054
2014 7.236529
2015 6.581104
2016 7.409875
2017 7.001441
2018 6.814621
2019 7.582515
2020 7.766470
2021 7.792571
2022 7.357711
ggplot(standard_dev_all_632, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Non-corrected standard deviation of SNOTEL 632 average temperatures for water years 2005-2021

MK & SS for 632 (non-corrected)

sd_mk_632 <- mk.test(standard_dev_all_632$sd_2)
print(sd_mk_632)
## 
##  Mann-Kendall trend test
## 
## data:  standard_dev_all_632$sd_2
## z = -1.6317, n = 31, p-value = 0.1028
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##            S         varS          tau 
##  -97.0000000 3461.6666667   -0.2086022
sd_sens_632 <- sens.slope(standard_dev_all_632$sd_2)
print(sd_sens_632)
## 
##  Sen's slope
## 
## data:  standard_dev_all_632$sd_2
## z = -1.6317, n = 31, p-value = 0.1028
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.034372524  0.003422909
## sample estimates:
## Sen's slope 
## -0.01583493

Corrected

632 Detrended (corrected)

#using the clean culled df:
#average water year temperature
yearly_wy_aver_632_ad <- snotel_632_adjusted %>% 
  group_by(waterYear) %>% 
  mutate(aver_ann_temp_ad = mean(temp_ad))
#Average temperature by day for all water years:
daily_wy_aver_632_ad <- yearly_wy_aver_632_ad %>% 
  group_by(daymonth) %>% 
  mutate(aver_day_temp_ad = mean(aver_ann_temp_ad))
#average mean temperature by day for the period of record:
daily_wy_aver_632_ad <- daily_wy_aver_632_ad %>% 
  group_by(daymonth) %>% 
  mutate(all_ave_temp_ad = mean(daily_wy_aver_632_ad$aver_day_temp_ad))
# try to show all years as means. 
daily_wy_aver2_632_ad <-daily_wy_aver_632_ad %>% 
  group_by(waterDay) %>%
  mutate(date_temp_ad = mean(temp_ad))
  
daily_wy_aver2_632_ad$date_temp_ad <- signif(daily_wy_aver2_632_ad$date_temp_ad,3) #reduce the sig figs
ggplot(daily_wy_aver2_632_ad, aes(x = waterDay, y = date_temp_ad))+
  geom_line(size= 0.7) +
  theme_few() +
  ylab('Average Daily temperature (°C)') + 
  xlab('Day of water year')

632 SS (corrected)

standard_dev_632_ad <- daily_wy_aver_632_ad %>% 
  group_by(waterYear) %>% 
  #filter(waterYear >= 1987 & waterYear <= 2021) %>% 
  mutate(residual = (all_ave_temp_ad-aver_ann_temp_ad)+temp_ad-aver_day_temp_ad) %>% 
  mutate(deviation = abs(residual-lag(residual)))
standard_dev_all_632_ad <- standard_dev_632_ad %>% 
  group_by(waterYear) %>% 
  mutate(nmbr = n())
standard_dev_all_632_ad <- standard_dev_all_632_ad %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)
standard_dev_all_632_ad %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1987 7.106416
1988 7.678134
1989 7.662133
1990 7.141729
1991 7.492618
1992 6.671512
1995 6.957618
1996 7.110780
1997 7.178235
1998 7.586041
1999 6.397699
2000 7.103150
2001 6.358660
2002 7.672831
2003 7.338249
2004 7.309361
2007 7.606845
2008 7.965266
2009 6.957636
2010 7.984148
2011 7.701741
2012 7.490245
2014 7.236308
2015 6.581364
2016 7.409996
2017 7.000722
2018 6.815246
2019 7.583475
2020 7.766635
2021 7.793272
2022 7.358050
ggplot(standard_dev_all_632_ad, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Morrisey-corrected standard deviation of SNOTEL 632 average temperatures for water years 1986-2021

MK & SS 632 (corrected)

sd_mk_632_ad <- mk.test(standard_dev_all_632_ad$sd_2)
print(sd_mk_632_ad)
## 
##  Mann-Kendall trend test
## 
## data:  standard_dev_all_632_ad$sd_2
## z = 0.9518, n = 31, p-value = 0.3412
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##            S         varS          tau 
##   57.0000000 3461.6666667    0.1225806
sd_sens_632_ad <- sens.slope(standard_dev_all_632_ad$sd_2)
print(sd_sens_632_ad)
## 
##  Sen's slope
## 
## data:  standard_dev_all_632_ad$sd_2
## z = 0.9518, n = 31, p-value = 0.3412
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.01086011  0.02505935
## sample estimates:
## Sen's slope 
## 0.008387789

Summer and Winter SD NOT-CORRECTED

Summer

summer_standard_dev_all_632 <- standard_dev_632 %>%
  filter(waterDay >= 244 & waterDay <= 335) %>%
  group_by(waterYear) %>% 
  mutate(nmbr = n())

summer_standard_dev_all_632 <- summer_standard_dev_all_632 %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)

summer_standard_dev_all_632 %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1987 2.114538
1988 2.228749
1989 2.856810
1990 2.412193
1991 2.352444
1992 2.653405
1995 3.167125
1996 2.098569
1997 2.061274
1998 2.877816
1999 2.505380
2000 1.633471
2001 2.886228
2002 2.116931
2003 2.603805
2004 2.098651
2007 2.150642
2008 2.108596
2009 2.560834
2010 2.129920
2011 1.670740
2012 1.544598
2014 1.887934
2015 2.090604
2016 2.291709
2017 1.837367
2018 1.515691
2019 2.268798
2020 2.134924
2021 1.997591
2022 1.865141
ggplot(summer_standard_dev_all_632, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Non-corrected standard deviation of SNOTEL 632 average summer temperatures for water years 2005-2021

summer MK & SS for 632 (non-corrected)

summer_sd_mk_632 <- mk.test(summer_standard_dev_all_632$sd_2)
print(summer_sd_mk_632)
## 
##  Mann-Kendall trend test
## 
## data:  summer_standard_dev_all_632$sd_2
## z = -2.6514, n = 31, p-value = 0.008015
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##            S         varS          tau 
## -157.0000000 3461.6666667   -0.3376344
summer_sd_sens_632 <- sens.slope(summer_standard_dev_all_632$sd_2)
print(summer_sd_sens_632)
## 
##  Sen's slope
## 
## data:  summer_standard_dev_all_632$sd_2
## z = -2.6514, n = 31, p-value = 0.008015
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.039099584 -0.005737351
## sample estimates:
## Sen's slope 
## -0.02039296

Winter

winter_standard_dev_all_632 <- standard_dev_632 %>%
  filter(waterDay >= 32 & waterDay <= 182) %>%
  group_by(waterYear) %>% 
  mutate(nmbr = n())

winter_standard_dev_all_632 <- winter_standard_dev_all_632 %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)

winter_standard_dev_all_632 %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1987 3.949897
1988 4.829572
1989 5.622923
1990 4.743667
1991 4.793091
1992 3.588398
1995 4.242979
1996 4.655088
1997 4.822418
1998 4.285365
1999 4.113247
2000 4.708228
2001 3.950374
2002 4.915860
2003 4.107473
2004 4.960115
2007 5.041141
2008 5.329581
2009 4.270156
2010 4.210609
2011 5.136480
2012 4.073954
2014 3.979979
2015 4.388198
2016 4.767132
2017 5.064705
2018 4.097621
2019 3.928620
2020 4.386364
2021 4.169782
2022 4.469723
ggplot(winter_standard_dev_all_632, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Non-corrected standard deviation of SNOTEL 632 average winter temperatures for water years 2005-2021

winter MK & SS for 632 (non-corrected)

winter_sd_mk_632 <- mk.test(winter_standard_dev_all_632$sd_2)
print(winter_sd_mk_632)
## 
##  Mann-Kendall trend test
## 
## data:  winter_standard_dev_all_632$sd_2
## z = -0.50989, n = 31, p-value = 0.6101
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##             S          varS           tau 
##  -31.00000000 3461.66666667   -0.06666667
winter_sd_sens_632 <- sens.slope(winter_standard_dev_all_632$sd_2)
print(winter_sd_sens_632)
## 
##  Sen's slope
## 
## data:  winter_standard_dev_all_632$sd_2
## z = -0.50989, n = 31, p-value = 0.6101
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.02934037  0.01517316
## sample estimates:
##  Sen's slope 
## -0.004429864

Summer and Winter SD CORRECTED

Summer

summer_standard_dev_all_632_ad <- standard_dev_632_ad %>% 
  filter(waterDay >= 244 & waterDay <= 335) %>%
  group_by(waterYear) %>% 
  mutate(nmbr = n())
summer_standard_dev_all_632_ad <- summer_standard_dev_all_632_ad %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)
summer_standard_dev_all_632_ad %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1987 1.906484
1988 2.015215
1989 2.570479
1990 2.171287
1991 2.126432
1992 2.395029
1995 2.849838
1996 1.882298
1997 1.856281
1998 2.592413
1999 2.262767
2000 1.464044
2001 2.625171
2002 1.897873
2003 2.334779
2004 2.097548
2007 2.150936
2008 2.109568
2009 2.560281
2010 2.129304
2011 1.670271
2012 1.543369
2014 1.887474
2015 2.090877
2016 2.290935
2017 1.836412
2018 1.515104
2019 2.269449
2020 2.135390
2021 1.997565
2022 1.865564
ggplot(summer_standard_dev_all_632_ad, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Morrisey-corrected standard deviation of SNOTEL 632 average summer temperatures for water years 1986-2021

summer MK & SS 632 (corrected)

summer_sd_mk_632_ad <- mk.test(summer_standard_dev_all_632_ad$sd_2)
print(summer_sd_mk_632_ad)
## 
##  Mann-Kendall trend test
## 
## data:  summer_standard_dev_all_632_ad$sd_2
## z = -1.5637, n = 31, p-value = 0.1179
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##        S     varS      tau 
##  -93.000 3461.667   -0.200
summer_sd_sens_632_ad <- sens.slope(summer_standard_dev_all_632_ad$sd_2)
print(summer_sd_sens_632_ad)
## 
##  Sen's slope
## 
## data:  summer_standard_dev_all_632_ad$sd_2
## z = -1.5637, n = 31, p-value = 0.1179
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.02586115  0.00291086
## sample estimates:
##  Sen's slope 
## -0.009778507

Winter

winter_standard_dev_all_632_ad <- standard_dev_632_ad %>% 
  filter(waterDay >= 32 & waterDay <= 182) %>%
  group_by(waterYear) %>% 
  mutate(nmbr = n())
winter_standard_dev_all_632_ad <- winter_standard_dev_all_632_ad %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)
winter_standard_dev_all_632_ad %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1987 3.822176
1988 4.707213
1989 5.460606
1990 4.581902
1991 4.707497
1992 3.453982
1995 4.078706
1996 4.474750
1997 4.640139
1998 4.120702
1999 3.953304
2000 4.510282
2001 3.819726
2002 4.720494
2003 3.965848
2004 4.959795
2007 5.041005
2008 5.330231
2009 4.270758
2010 4.211804
2011 5.136593
2012 4.075229
2014 3.980001
2015 4.388367
2016 4.767229
2017 5.064022
2018 4.099260
2019 3.931958
2020 4.386891
2021 4.171687
2022 4.470494
ggplot(winter_standard_dev_all_632_ad, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Morrisey-corrected standard deviation of SNOTEL 632 average winter temperatures for water years 1986-2021

winter MK & SS 632 (corrected)

winter_sd_mk_632_ad <- mk.test(winter_standard_dev_all_632_ad$sd_2)
print(winter_sd_mk_632_ad)
## 
##  Mann-Kendall trend test
## 
## data:  winter_standard_dev_all_632_ad$sd_2
## z = 0.067986, n = 31, p-value = 0.9458
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##            S         varS          tau 
## 5.000000e+00 3.461667e+03 1.075269e-02
winter_sd_sens_632_ad <- sens.slope(winter_standard_dev_all_632_ad$sd_2)
print(winter_sd_sens_632_ad)
## 
##  Sen's slope
## 
## data:  winter_standard_dev_all_632_ad$sd_2
## z = 0.067986, n = 31, p-value = 0.9458
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.02224021  0.02070360
## sample estimates:
## Sen's slope 
## 0.001106788

Spring and Fall SD NOT-CORRECTED

Spring

spring_standard_dev_all_632 <- standard_dev_632 %>%
  filter(waterDay >= 183 & waterDay <= 243) %>%
  group_by(waterYear) %>% 
  mutate(nmbr = n())

spring_standard_dev_all_632 <- spring_standard_dev_all_632 %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)

spring_standard_dev_all_632 %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1987 3.379616
1988 4.027329
1989 4.146475
1990 2.583840
1991 4.609946
1992 2.655814
1995 4.040804
1996 4.905394
1997 5.104705
1998 4.744003
1999 4.615837
2000 4.403973
2001 4.024889
2002 3.342872
2003 4.798929
2004 3.265030
2007 3.479188
2008 4.072262
2009 4.500348
2010 4.704224
2011 3.860626
2012 3.586672
2014 4.415046
2015 2.697496
2016 3.402634
2017 3.573469
2018 3.689900
2019 2.953121
2020 3.814847
2021 3.236652
2022 4.193475
ggplot(spring_standard_dev_all_632, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Non-corrected standard deviation of SNOTEL 632 average spring temperatures for water years 2005-2021

spring MK & SS for 632 (non-corrected)

spring_sd_mk_632 <- mk.test(spring_standard_dev_all_632$sd_2)
print(spring_sd_mk_632)
## 
##  Mann-Kendall trend test
## 
## data:  spring_standard_dev_all_632$sd_2
## z = -1.1558, n = 31, p-value = 0.2478
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##            S         varS          tau 
##  -69.0000000 3461.6666667   -0.1483871
spring_sd_sens_632 <- sens.slope(spring_standard_dev_all_632$sd_2)
print(spring_sd_sens_632)
## 
##  Sen's slope
## 
## data:  spring_standard_dev_all_632$sd_2
## z = -1.1558, n = 31, p-value = 0.2478
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.05096275  0.01342854
## sample estimates:
## Sen's slope 
## -0.01902395

Fall

Fall is split each water year in the middle of the season. This analysis splits the fall season between the preceding water year and the subsequent water year.

fall_standard_dev_all_632 <- standard_dev_632 %>%
  filter(waterDay >= 336 | waterDay <= 31) %>% 
  group_by(waterYear) %>% 
  mutate(nmbr = n())

fall_standard_dev_all_632 <- fall_standard_dev_all_632 %>% 
  #group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)

fall_standard_dev_all_632 %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1987 3.348217
1988 3.200892
1989 2.827929
1990 4.691608
1991 3.774883
1992 4.294848
1995 4.450046
1996 3.804044
1997 5.397835
1998 5.376137
1999 3.808616
2000 3.680717
2001 4.227670
2002 3.324431
2003 4.316988
2004 3.011663
2007 4.372880
2008 3.370613
2009 3.256481
2010 5.374149
2011 3.740049
2012 4.142702
2014 4.863549
2015 2.678368
2016 3.111886
2017 2.942115
2018 3.212983
2019 4.409356
2020 5.423782
2021 3.900049
2022 4.648080
ggplot(fall_standard_dev_all_632, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Non-corrected standard deviation of SNOTEL 632 average fall temperatures for water years 2005-2021. Note that the season is split by the water year.

fall MK & SS for 632 (non-corrected)

fall_sd_mk_632 <- mk.test(fall_standard_dev_all_632$sd_2)
print(fall_sd_mk_632)
## 
##  Mann-Kendall trend test
## 
## data:  fall_standard_dev_all_632$sd_2
## z = 0.20396, n = 31, p-value = 0.8384
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##            S         varS          tau 
## 1.300000e+01 3.461667e+03 2.795699e-02
fall_sd_sens_632 <- sens.slope(fall_standard_dev_all_632$sd_2)
print(fall_sd_sens_632)
## 
##  Sen's slope
## 
## data:  fall_standard_dev_all_632$sd_2
## z = 0.20396, n = 31, p-value = 0.8384
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.03314985  0.04426072
## sample estimates:
## Sen's slope 
## 0.003269961

Spring and Fall SD CORRECTED

Spring

spring_standard_dev_all_632_ad <- standard_dev_632_ad %>% 
  filter(waterDay >= 183 & waterDay <= 243) %>%
  group_by(waterYear) %>% 
  mutate(nmbr = n())
spring_standard_dev_all_632_ad <- spring_standard_dev_all_632_ad %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)
spring_standard_dev_all_632_ad %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1987 3.140471
1988 3.724888
1989 3.821839
1990 2.375915
1991 4.299888
1992 2.438047
1995 3.765580
1996 4.516104
1997 4.765257
1998 4.397177
1999 4.307069
2000 4.029641
2001 3.797386
2002 3.052889
2003 4.426674
2004 3.264222
2007 3.479411
2008 4.072291
2009 4.500074
2010 4.703848
2011 3.860188
2012 3.586745
2014 4.414457
2015 2.696812
2016 3.401516
2017 3.573816
2018 3.689933
2019 2.953748
2020 3.814805
2021 3.235991
2022 4.193497
ggplot(spring_standard_dev_all_632_ad, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Morrisey-corrected standard deviation of SNOTEL 632 average spring temperatures for water years 1986-2021

spring MK & SS 632 (corrected)

spring_sd_mk_632_ad <- mk.test(spring_standard_dev_all_632_ad$sd_2)
print(spring_sd_mk_632_ad)
## 
##  Mann-Kendall trend test
## 
## data:  spring_standard_dev_all_632_ad$sd_2
## z = -0.27194, n = 31, p-value = 0.7857
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##             S          varS           tau 
##  -17.00000000 3461.66666667   -0.03655914
spring_sd_sens_632_ad <- sens.slope(spring_standard_dev_all_632_ad$sd_2)
print(spring_sd_sens_632_ad)
## 
##  Sen's slope
## 
## data:  spring_standard_dev_all_632_ad$sd_2
## z = -0.27194, n = 31, p-value = 0.7857
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.03310501  0.02412555
## sample estimates:
##  Sen's slope 
## -0.004091998

Fall

fall_standard_dev_all_632_ad <- standard_dev_632_ad %>% 
  filter(waterDay >= 336 | waterDay <= 31) %>%
  group_by(waterYear) %>% 
  mutate(nmbr = n())
fall_standard_dev_all_632_ad <- fall_standard_dev_all_632_ad %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)
fall_standard_dev_all_632_ad %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1987 3.087734
1988 2.926167
1989 2.569033
1990 4.306655
1991 3.486359
1992 3.988918
1995 4.064499
1996 3.487977
1997 4.987110
1998 4.956360
1999 3.494303
2000 3.350504
2001 3.866035
2002 3.036894
2003 3.964220
2004 3.009056
2007 4.370690
2008 3.370602
2009 3.254927
2010 5.374179
2011 3.739585
2012 4.141986
2014 4.860922
2015 2.676858
2016 3.111728
2017 2.939910
2018 3.212557
2019 4.407603
2020 5.423961
2021 3.900087
2022 4.647145
ggplot(fall_standard_dev_all_632_ad, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Morrisey-corrected standard deviation of SNOTEL 632 average fall temperatures for water years 1986-2021. Note that the fall season is split by the water year.

fall MK & SS 632 (corrected)

fall_sd_mk_632_ad <- mk.test(fall_standard_dev_all_632_ad$sd_2)
print(fall_sd_mk_632_ad)
## 
##  Mann-Kendall trend test
## 
## data:  fall_standard_dev_all_632_ad$sd_2
## z = 1.0538, n = 31, p-value = 0.292
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##            S         varS          tau 
##   63.0000000 3461.6666667    0.1354839
fall_sd_sens_632_ad <- sens.slope(fall_standard_dev_all_632_ad$sd_2)
print(fall_sd_sens_632_ad)
## 
##  Sen's slope
## 
## data:  fall_standard_dev_all_632_ad$sd_2
## z = 1.0538, n = 31, p-value = 0.292
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.01653090  0.05372353
## sample estimates:
## Sen's slope 
##  0.01873226

Red Mountain Pass 713

Morrisey 8/18/2004

snotel_713 <- SNOTEL_san_juan_Area %>% 
  filter(site_id == "713")
#str(snotel_713) # check the date, usually a character.  

snotel_713$Date <- as.Date(snotel_713$date) #change date from character to date format, capitalize to work with Water year functon from NWIS.

#THIS WILL CHANGE FOR EACH STATION
snotel_713_clean <- snotel_713 %>% # filter for the timeframe
  filter(Date >= "1979-10-01" & Date <= "2022-09-30") %>%
  #filter(temperature_mean >= -30 & temperature_mean <= 20) %>% # removing outliers   
  addWaterYear() %>% 
  mutate(daymonth = format(as.Date(Date), "%d-%m")) %>% 
  na.omit()

#adding water day using difftime (SUPER COOL. example from [this](https://stackoverflow.com/questions/48123049/create-day-index-based-on-water-year))

snotel_713_clean <- snotel_713_clean %>% 
  group_by(waterYear)%>% 
  mutate(waterDay = (as.integer(difftime(Date, ymd(paste0(waterYear - 1 ,'-09-30')), units = "days"))))
# Check for outliers

ggplot(snotel_713_clean, aes(x = Date, y = temperature_mean)) +
  geom_point() + #lwd = 2) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('Daily temperature (°C)') + 
  xlab('Date')

snotel_713_clean <- snotel_713_clean %>% 
  mutate(temp_diff = abs(temperature_min - temperature_max)) %>% 
  filter(temperature_mean > -40) %>% 
  filter(temperature_mean < 25)
ggplot(snotel_713_clean, aes(x = Date, y = temp_diff)) + 
  geom_point() + #lwd = 2) +
  theme_few() +
  #geom_smooth(method = "lm", se=FALSE) +
  ylab('Daily temperature varience (°C)') + 
  xlab('Date')

Per Steven’s advice: :If there are more than 15 missing days, then…remove that year”

# filtering for temperature anomalies
snotel_713_cull_count <- snotel_713_clean %>% 
  filter(temperature_min > -40) %>% 
  count(waterYear)

snotel_713_cull_count
## # A tibble: 42 x 2
## # Groups:   waterYear [42]
##    waterYear     n
##        <dbl> <int>
##  1      1981   189
##  2      1982   287
##  3      1983   319
##  4      1984   360
##  5      1985   362
##  6      1986   364
##  7      1987   263
##  8      1988   282
##  9      1989   228
## 10      1990   365
## # ... with 32 more rows
# filtering for too few observations in a year
snotel_713_cull_count_days <- snotel_713_clean %>% 
  group_by(waterYear) %>% 
  count(waterYear) %>% 
  filter(n < 350)

snotel_713_cull_count_days
## # A tibble: 6 x 2
## # Groups:   waterYear [6]
##   waterYear     n
##       <dbl> <int>
## 1      1981   189
## 2      1982   287
## 3      1983   319
## 4      1987   315
## 5      1989   263
## 6      1994   308

1981, 1982, 1983, 1987, 1989, 1994 need to be culled. 1984 & 1985 are too low.

snotel_713_clean_culled <- snotel_713_clean %>% 
  filter(waterYear > "1985" & waterYear != "1987" & waterYear != "1989" & waterYear != "1994")# & waterYear != "1993" & waterYear != "1994" & waterYear != "2021" & waterYear != "2022") & waterYear != "2014") #%>% 
  #filter(temperature_mean > -49)

ggplot(snotel_713_clean_culled, aes(x = Date, y = temp_diff)) + 
  geom_point() + #lwd = 2) +
  theme_few() +
  #geom_smooth(method = "lm", se=FALSE) +
  ylab('Daily temperature varience (°C)') + 
  xlab('Date')

ggplot(snotel_713_clean_culled, aes(x = Date, y = temperature_mean)) + 
  geom_point() + #lwd = 2) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('Daily temperature (°C)') + 
  xlab('Date')

temp_713_xts <- xts(snotel_713_clean_culled$temperature_mean, order.by = snotel_713_clean_culled$Date)

dygraph(temp_713_xts) %>%
  dyAxis("y", label = "Daily mean temperature (°C)") 
snotel_713_clean_culled <- snotel_713_clean_culled %>% 
  filter(temperature_mean < 19.3)

temp_713_xts <- xts(snotel_713_clean_culled$temperature_mean, order.by = snotel_713_clean_culled$Date)

dygraph(temp_713_xts) %>%
  dyAxis("y", label = "Daily mean temperature (°C)") 

Red Mountain Pass 713

Morrisey 8/18/2004

snotel_713_adjusted <- snotel_713_clean_culled %>%
  mutate(temp_ad = if_else(Date < "2004-08-18", ((5.3*10^(-7))*(temperature_mean^(4))+(3.72*10^(-5))*(temperature_mean^(3))-(2.16*10^(-3))*(temperature_mean^(2))-(7.32*10^(-2))*(temperature_mean)+1.37)+temperature_mean, temperature_mean))

Non-corrected

713 Detrended

#using the clean culled df:

#average water year temperature

yearly_wy_aver_713 <- snotel_713_adjusted %>% 
  group_by(waterYear) %>% 
  mutate(aver_ann_temp = mean(temperature_mean))

#Average temperature by day for all water years:

daily_wy_aver_713 <- yearly_wy_aver_713 %>% 
  group_by(daymonth) %>% 
  mutate(aver_day_temp = mean(aver_ann_temp))

#average mean temperature by day for the period of record:

daily_wy_aver_713 <- daily_wy_aver_713 %>% 
  group_by(daymonth) %>% 
  mutate(all_ave_temp = mean(daily_wy_aver_713$aver_day_temp))

# try to show all years as means. 
daily_wy_aver2_713 <-daily_wy_aver_713 %>% 
  group_by(waterDay) %>%
  mutate(date_temp = mean(temperature_mean))
  

daily_wy_aver2_713$date_temp <- signif(daily_wy_aver2_713$date_temp,3) #reduce the sig figs


ggplot(daily_wy_aver2_713, aes(x = waterDay, y = date_temp))+
  geom_line(size= 0.7) +
  theme_few() +
  ylab('Average Daily temperature (°C)') + 
  xlab('Day of water year')

713 SD

standard_dev_713 <- daily_wy_aver_713 %>% 
  group_by(waterYear) %>% 
  mutate(residual = (all_ave_temp-aver_ann_temp)+temperature_mean-aver_day_temp) %>% 
  mutate(deviation = abs(residual-lag(residual)))

standard_dev_all_713 <- standard_dev_713 %>% 
  group_by(waterYear) %>% 
  mutate(nmbr = n())

standard_dev_all_713 <- standard_dev_all_713 %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)

standard_dev_all_713 %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1986 7.022683
1988 9.344095
1990 7.761743
1991 7.768555
1992 7.212083
1993 7.716280
1995 7.336781
1996 7.731429
1997 7.947757
1998 8.198019
1999 6.921528
2000 7.680921
2001 8.089853
2002 8.395619
2003 7.952564
2004 7.777488
2005 7.151965
2006 7.312223
2007 7.636775
2008 7.908986
2009 6.940732
2010 7.877650
2011 7.730288
2012 7.531887
2013 8.195738
2014 7.284701
2015 6.638343
2016 7.380700
2017 7.097935
2018 7.002862
2019 7.626598
2020 7.810018
2021 7.817233
2022 7.339213
ggplot(standard_dev_all_713, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Non-corrected standard deviation of SNOTEL 713 average temperatures for water years 2005-2021

MK & SS for 713 (non-corrected)

sd_mk_713 <- mk.test(standard_dev_all_713$sd_2)
print(sd_mk_713)
## 
##  Mann-Kendall trend test
## 
## data:  standard_dev_all_713$sd_2
## z = -1.1563, n = 34, p-value = 0.2476
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##          S       varS        tau 
##  -79.00000 4550.33333   -0.14082
sd_sens_713 <- sens.slope(standard_dev_all_713$sd_2)
print(sd_sens_713)
## 
##  Sen's slope
## 
## data:  standard_dev_all_713$sd_2
## z = -1.1563, n = 34, p-value = 0.2476
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.028289222  0.006454843
## sample estimates:
##  Sen's slope 
## -0.008980292

Corrected

713 Detrended (corrected)

#using the clean culled df:
#average water year temperature
yearly_wy_aver_713_ad <- snotel_713_adjusted %>% 
  group_by(waterYear) %>% 
  mutate(aver_ann_temp_ad = mean(temp_ad))
#Average temperature by day for all water years:
daily_wy_aver_713_ad <- yearly_wy_aver_713_ad %>% 
  group_by(daymonth) %>% 
  mutate(aver_day_temp_ad = mean(aver_ann_temp_ad))
#average mean temperature by day for the period of record:
daily_wy_aver_713_ad <- daily_wy_aver_713_ad %>% 
  group_by(daymonth) %>% 
  mutate(all_ave_temp_ad = mean(daily_wy_aver_713_ad$aver_day_temp_ad))
# try to show all years as means. 
daily_wy_aver2_713_ad <-daily_wy_aver_713_ad %>% 
  group_by(waterDay) %>%
  mutate(date_temp_ad = mean(temp_ad))
  
daily_wy_aver2_713_ad$date_temp_ad <- signif(daily_wy_aver2_713_ad$date_temp_ad,3) #reduce the sig figs
ggplot(daily_wy_aver2_713_ad, aes(x = waterDay, y = date_temp_ad))+
  geom_line(size= 0.7) +
  theme_few() +
  ylab('Average Daily temperature (°C)') + 
  xlab('Day of water year')

713 SS (corrected)

standard_dev_713_ad <- daily_wy_aver_713_ad %>% 
  group_by(waterYear) %>% 
  #filter(waterYear >= 1987 & waterYear <= 2021) %>% 
  mutate(residual = (all_ave_temp_ad-aver_ann_temp_ad)+temp_ad-aver_day_temp_ad) %>% 
  mutate(deviation = abs(residual-lag(residual)))
standard_dev_all_713_ad <- standard_dev_713_ad %>% 
  group_by(waterYear) %>% 
  mutate(nmbr = n())
standard_dev_all_713_ad <- standard_dev_all_713_ad %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)
standard_dev_all_713_ad %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1986 6.564707
1988 8.872885
1990 7.267850
1991 7.311859
1992 6.739882
1993 7.221869
1995 6.846024
1996 7.223659
1997 7.456352
1998 7.661532
1999 6.466454
2000 7.159552
2001 7.557097
2002 7.840372
2003 7.411227
2004 7.238021
2005 7.151835
2006 7.312105
2007 7.636625
2008 7.909548
2009 6.940894
2010 7.878182
2011 7.730889
2012 7.532385
2013 8.196125
2014 7.284711
2015 6.639012
2016 7.380681
2017 7.097919
2018 7.003100
2019 7.627224
2020 7.810395
2021 7.817455
2022 7.339782
ggplot(standard_dev_all_713_ad, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Morrisey-corrected standard deviation of SNOTEL 713 average temperatures for water years 1986-2021

MK & SS 713 (corrected)

sd_mk_713_ad <- mk.test(standard_dev_all_713_ad$sd_2)
print(sd_mk_713_ad)
## 
##  Mann-Kendall trend test
## 
## data:  standard_dev_all_713_ad$sd_2
## z = 1.4231, n = 34, p-value = 0.1547
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##            S         varS          tau 
##   97.0000000 4550.3333333    0.1729055
sd_sens_713_ad <- sens.slope(standard_dev_all_713_ad$sd_2)
print(sd_sens_713_ad)
## 
##  Sen's slope
## 
## data:  standard_dev_all_713_ad$sd_2
## z = 1.4231, n = 34, p-value = 0.1547
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.005520634  0.030221234
## sample estimates:
## Sen's slope 
##  0.01194811

Summer and Winter SD NOT-CORRECTED

Summer

summer_standard_dev_all_713 <- standard_dev_713 %>%
  filter(waterDay >= 244 & waterDay <= 335) %>%
  group_by(waterYear) %>% 
  mutate(nmbr = n())

summer_standard_dev_all_713 <- summer_standard_dev_all_713 %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)

summer_standard_dev_all_713 %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1986 2.139350
1988 2.406641
1990 2.336632
1991 2.159360
1992 2.668072
1993 2.909805
1995 3.136742
1996 2.080807
1997 2.074595
1998 2.957249
1999 2.563673
2000 1.773197
2001 2.337354
2002 2.294479
2003 2.670927
2004 2.236947
2005 2.812376
2006 1.847511
2007 2.321335
2008 2.175636
2009 2.588092
2010 2.233155
2011 1.878950
2012 1.571661
2013 1.836963
2014 1.930513
2015 2.189941
2016 2.408465
2017 1.768913
2018 1.593608
2019 2.343849
2020 2.338442
2021 2.070922
2022 1.836083
ggplot(summer_standard_dev_all_713, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Non-corrected standard deviation of SNOTEL 713 average summer temperatures for water years 2005-2021

summer MK & SS for 713 (non-corrected)

summer_sd_mk_713 <- mk.test(summer_standard_dev_all_713$sd_2)
print(summer_sd_mk_713)
## 
##  Mann-Kendall trend test
## 
## data:  summer_standard_dev_all_713$sd_2
## z = -2.3423, n = 34, p-value = 0.01917
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##            S         varS          tau 
## -159.0000000 4550.3333333   -0.2834225
summer_sd_sens_713 <- sens.slope(summer_standard_dev_all_713$sd_2)
print(summer_sd_sens_713)
## 
##  Sen's slope
## 
## data:  summer_standard_dev_all_713$sd_2
## z = -2.3423, n = 34, p-value = 0.01917
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.03129544 -0.00304958
## sample estimates:
## Sen's slope 
## -0.01695302

Winter

winter_standard_dev_all_713 <- standard_dev_713 %>%
  filter(waterDay >= 32 & waterDay <= 182) %>%
  group_by(waterYear) %>% 
  mutate(nmbr = n())

winter_standard_dev_all_713 <- winter_standard_dev_all_713 %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)

winter_standard_dev_all_713 %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1986 4.645769
1988 4.862335
1990 4.799414
1991 4.611532
1992 3.437104
1993 3.834979
1995 4.170829
1996 4.759220
1997 5.077174
1998 4.272264
1999 4.270013
2000 4.764869
2001 3.924418
2002 4.865435
2003 4.117591
2004 5.142411
2005 3.839183
2006 4.571793
2007 5.128933
2008 5.379638
2009 4.271019
2010 4.221595
2011 5.159513
2012 4.142368
2013 5.487970
2014 4.088167
2015 4.383886
2016 4.562763
2017 5.084893
2018 4.324668
2019 3.901566
2020 4.282591
2021 4.146951
2022 4.474188
ggplot(winter_standard_dev_all_713, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Non-corrected standard deviation of SNOTEL 713 average winter temperatures for water years 2005-2021

winter MK & SS for 713 (non-corrected)

winter_sd_mk_713 <- mk.test(winter_standard_dev_all_713$sd_2)
print(winter_sd_mk_713)
## 
##  Mann-Kendall trend test
## 
## data:  winter_standard_dev_all_713$sd_2
## z = -0.059298, n = 34, p-value = 0.9527
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##             S          varS           tau 
## -5.000000e+00  4.550333e+03 -8.912656e-03
winter_sd_sens_713 <- sens.slope(winter_standard_dev_all_713$sd_2)
print(winter_sd_sens_713)
## 
##  Sen's slope
## 
## data:  winter_standard_dev_all_713$sd_2
## z = -0.059298, n = 34, p-value = 0.9527
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.01975444  0.01876824
## sample estimates:
##   Sen's slope 
## -0.0009183803

Summer and Winter SD CORRECTED

Summer

summer_standard_dev_all_713_ad <- standard_dev_713_ad %>% 
  filter(waterDay >= 244 & waterDay <= 335) %>%
  group_by(waterYear) %>% 
  mutate(nmbr = n())
summer_standard_dev_all_713_ad <- summer_standard_dev_all_713_ad %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)
summer_standard_dev_all_713_ad %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1986 1.930084
1988 2.180706
1990 2.105669
1991 1.954594
1992 2.412392
1993 2.630912
1995 2.830362
1996 1.872357
1997 1.873575
1998 2.671939
1999 2.322147
2000 1.592045
2001 2.114503
2002 2.061693
2003 2.398854
2004 2.115890
2005 2.812773
2006 1.848523
2007 2.321810
2008 2.174991
2009 2.588728
2010 2.233945
2011 1.880062
2012 1.571792
2013 1.837758
2014 1.932501
2015 2.191267
2016 2.407967
2017 1.767961
2018 1.592847
2019 2.344936
2020 2.338940
2021 2.070055
2022 1.835797
ggplot(summer_standard_dev_all_713_ad, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Morrisey-corrected standard deviation of SNOTEL 713 average summer temperatures for water years 1986-2021

summer MK & SS 713 (corrected)

summer_sd_mk_713_ad <- mk.test(summer_standard_dev_all_713_ad$sd_2)
print(summer_sd_mk_713_ad)
## 
##  Mann-Kendall trend test
## 
## data:  summer_standard_dev_all_713_ad$sd_2
## z = -1.097, n = 34, p-value = 0.2726
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##            S         varS          tau 
##  -75.0000000 4550.3333333   -0.1336898
summer_sd_sens_713_ad <- sens.slope(summer_standard_dev_all_713_ad$sd_2)
print(summer_sd_sens_713_ad)
## 
##  Sen's slope
## 
## data:  summer_standard_dev_all_713_ad$sd_2
## z = -1.097, n = 34, p-value = 0.2726
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.019882565  0.006751377
## sample estimates:
##  Sen's slope 
## -0.005790124

Winter

winter_standard_dev_all_713_ad <- standard_dev_713_ad %>% 
  filter(waterDay >= 32 & waterDay <= 182) %>%
  group_by(waterYear) %>% 
  mutate(nmbr = n())
winter_standard_dev_all_713_ad <- winter_standard_dev_all_713_ad %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)
winter_standard_dev_all_713_ad %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1986 4.494194
1988 4.789179
1990 4.649945
1991 4.527027
1992 3.325878
1993 3.732987
1995 4.029498
1996 4.612093
1997 4.916879
1998 4.137738
1999 4.130153
2000 4.590334
2001 3.816445
2002 4.705872
2003 3.993888
2004 4.979402
2005 3.839378
2006 4.572419
2007 5.128989
2008 5.380547
2009 4.271172
2010 4.223062
2011 5.160807
2012 4.143686
2013 5.489179
2014 4.088688
2015 4.384924
2016 4.562407
2017 5.085927
2018 4.325059
2019 3.903572
2020 4.283199
2021 4.148313
2022 4.476398
ggplot(winter_standard_dev_all_713_ad, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Morrisey-corrected standard deviation of SNOTEL 713 average winter temperatures for water years 1986-2021

winter MK & SS 713 (corrected)

winter_sd_mk_713_ad <- mk.test(winter_standard_dev_all_713_ad$sd_2)
print(winter_sd_mk_713_ad)
## 
##  Mann-Kendall trend test
## 
## data:  winter_standard_dev_all_713_ad$sd_2
## z = 0.44473, n = 34, p-value = 0.6565
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##            S         varS          tau 
## 3.100000e+01 4.550333e+03 5.525847e-02
winter_sd_sens_713_ad <- sens.slope(winter_standard_dev_all_713_ad$sd_2)
print(winter_sd_sens_713_ad)
## 
##  Sen's slope
## 
## data:  winter_standard_dev_all_713_ad$sd_2
## z = 0.44473, n = 34, p-value = 0.6565
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.01433478  0.02256352
## sample estimates:
## Sen's slope 
## 0.005733297

Spring and Fall SD NOT-CORRECTED

Spring

spring_standard_dev_all_713 <- standard_dev_713 %>%
  filter(waterDay >= 183 & waterDay <= 243) %>%
  group_by(waterYear) %>% 
  mutate(nmbr = n())

spring_standard_dev_all_713 <- spring_standard_dev_all_713 %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)

spring_standard_dev_all_713 %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1986 3.987625
1988 4.339696
1990 2.988416
1991 4.636905
1992 3.055783
1993 4.129777
1995 3.725332
1996 5.121853
1997 5.169886
1998 4.717327
1999 4.718035
2000 4.594787
2001 4.625703
2002 3.284972
2003 4.842675
2004 3.629728
2005 4.253004
2006 3.582915
2007 3.571430
2008 4.268627
2009 4.580298
2010 4.665634
2011 4.170750
2012 3.733568
2013 4.414930
2014 4.582605
2015 2.751522
2016 3.342001
2017 3.823737
2018 3.902226
2019 3.109872
2020 3.890284
2021 3.268563
2022 4.362726
ggplot(spring_standard_dev_all_713, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Non-corrected standard deviation of SNOTEL 713 average spring temperatures for water years 2005-2021

spring MK & SS for 713 (non-corrected)

spring_sd_mk_713 <- mk.test(spring_standard_dev_all_713$sd_2)
print(spring_sd_mk_713)
## 
##  Mann-Kendall trend test
## 
## data:  spring_standard_dev_all_713$sd_2
## z = -1.4231, n = 34, p-value = 0.1547
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##            S         varS          tau 
##  -97.0000000 4550.3333333   -0.1729055
spring_sd_sens_713 <- sens.slope(spring_standard_dev_all_713$sd_2)
print(spring_sd_sens_713)
## 
##  Sen's slope
## 
## data:  spring_standard_dev_all_713$sd_2
## z = -1.4231, n = 34, p-value = 0.1547
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.041583727  0.007691066
## sample estimates:
## Sen's slope 
## -0.01825385

Fall

Fall is split each water year in the middle of the season. This analysis splits the fall season between the preceding water year and the subsequent water year.

fall_standard_dev_all_713 <- standard_dev_713 %>%
  filter(waterDay >= 336 | waterDay <= 31) %>% 
  group_by(waterYear) %>% 
  mutate(nmbr = n())

fall_standard_dev_all_713 <- fall_standard_dev_all_713 %>% 
  #group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)

fall_standard_dev_all_713 %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1986 3.041874
1988 11.319777
1990 4.998816
1991 3.562288
1992 4.788933
1993 3.270933
1995 4.400006
1996 4.096544
1997 5.659732
1998 5.213459
1999 3.927945
2000 3.852229
2001 4.403187
2002 3.493702
2003 4.424034
2004 3.373742
2005 4.042195
2006 3.128732
2007 4.465923
2008 3.602443
2009 3.517433
2010 5.505568
2011 3.720441
2012 4.141699
2013 3.989313
2014 5.085721
2015 2.789078
2016 3.243229
2017 3.176570
2018 3.402494
2019 4.549307
2020 5.866486
2021 4.036619
2022 4.792673
ggplot(fall_standard_dev_all_713, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Non-corrected standard deviation of SNOTEL 713 average fall temperatures for water years 2005-2021. Note that the season is split by the water year.

fall MK & SS for 713 (non-corrected)

fall_sd_mk_713 <- mk.test(fall_standard_dev_all_713$sd_2)
print(fall_sd_mk_713)
## 
##  Mann-Kendall trend test
## 
## data:  fall_standard_dev_all_713$sd_2
## z = -0.47438, n = 34, p-value = 0.6352
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##             S          varS           tau 
##  -33.00000000 4550.33333333   -0.05882353
fall_sd_sens_713 <- sens.slope(fall_standard_dev_all_713$sd_2)
print(fall_sd_sens_713)
## 
##  Sen's slope
## 
## data:  fall_standard_dev_all_713$sd_2
## z = -0.47438, n = 34, p-value = 0.6352
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.04821824  0.02519322
## sample estimates:
## Sen's slope 
## -0.01167551

Spring and Fall SD CORRECTED

Spring

spring_standard_dev_all_713_ad <- standard_dev_713_ad %>% 
  filter(waterDay >= 183 & waterDay <= 243) %>%
  group_by(waterYear) %>% 
  mutate(nmbr = n())
spring_standard_dev_all_713_ad <- spring_standard_dev_all_713_ad %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)
spring_standard_dev_all_713_ad %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1986 3.705919
1988 4.033226
1990 2.763689
1991 4.354219
1992 2.820131
1993 3.837928
1995 3.484426
1996 4.751809
1997 4.851821
1998 4.396733
1999 4.421978
2000 4.228807
2001 4.282810
2002 3.010500
2003 4.490610
2004 3.352125
2005 4.253004
2006 3.582915
2007 3.571430
2008 4.268149
2009 4.580298
2010 4.665634
2011 4.170750
2012 3.733714
2013 4.414930
2014 4.582605
2015 2.751522
2016 3.341185
2017 3.823737
2018 3.902226
2019 3.109872
2020 3.889988
2021 3.268563
2022 4.362726
ggplot(spring_standard_dev_all_713_ad, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Morrisey-corrected standard deviation of SNOTEL 713 average spring temperatures for water years 1986-2021

spring MK & SS 713 (corrected)

spring_sd_mk_713_ad <- mk.test(spring_standard_dev_all_713_ad$sd_2)
print(spring_sd_mk_713_ad)
## 
##  Mann-Kendall trend test
## 
## data:  spring_standard_dev_all_713_ad$sd_2
## z = -0.26684, n = 34, p-value = 0.7896
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##             S          varS           tau 
##  -19.00000000 4550.33333333   -0.03386809
spring_sd_sens_713_ad <- sens.slope(spring_standard_dev_all_713_ad$sd_2)
print(spring_sd_sens_713_ad)
## 
##  Sen's slope
## 
## data:  spring_standard_dev_all_713_ad$sd_2
## z = -0.26684, n = 34, p-value = 0.7896
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.02524236  0.02024073
## sample estimates:
##  Sen's slope 
## -0.004774607

Fall

fall_standard_dev_all_713_ad <- standard_dev_713_ad %>% 
  filter(waterDay >= 336 | waterDay <= 31) %>%
  group_by(waterYear) %>% 
  mutate(nmbr = n())
fall_standard_dev_all_713_ad <- fall_standard_dev_all_713_ad %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)
fall_standard_dev_all_713_ad %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1986 2.793367
1988 11.084406
1990 4.610893
1991 3.289681
1992 4.479808
1993 3.006810
1995 4.036656
1996 3.779810
1997 5.266877
1998 4.821033
1999 3.619422
2000 3.530741
2001 4.044899
2002 3.209487
2003 4.077833
2004 3.126095
2005 4.041086
2006 3.128409
2007 4.466275
2008 3.604342
2009 3.519229
2010 5.507317
2011 3.722873
2012 4.142178
2013 3.988762
2014 5.084391
2015 2.791467
2016 3.241462
2017 3.173011
2018 3.405705
2019 4.550280
2020 5.867505
2021 4.035025
2022 4.793700
ggplot(fall_standard_dev_all_713_ad, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Morrisey-corrected standard deviation of SNOTEL 713 average fall temperatures for water years 1986-2021. Note that the fall season is split by the water year.

fall MK & SS 713 (corrected)

fall_sd_mk_713_ad <- mk.test(fall_standard_dev_all_713_ad$sd_2)
print(fall_sd_mk_713_ad)
## 
##  Mann-Kendall trend test
## 
## data:  fall_standard_dev_all_713_ad$sd_2
## z = 0.20754, n = 34, p-value = 0.8356
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##            S         varS          tau 
## 1.500000e+01 4.550333e+03 2.673797e-02
fall_sd_sens_713_ad <- sens.slope(fall_standard_dev_all_713_ad$sd_2)
print(fall_sd_sens_713_ad)
## 
##  Sen's slope
## 
## data:  fall_standard_dev_all_713_ad$sd_2
## z = 0.20754, n = 34, p-value = 0.8356
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.03417429  0.03880180
## sample estimates:
## Sen's slope 
## 0.004462431

Scotch Creek 739

Morrisey 6/15/2004

snotel_739 <- SNOTEL_san_juan_Area %>% 
  filter(site_id == "739")
#str(snotel_739) # check the date, usually a character.  

snotel_739$Date <- as.Date(snotel_739$date) #change date from character to date format, capitalize to work with Water year functon from NWIS.

#THIS WILL CHANGE FOR EACH STATION
snotel_739_clean <- snotel_739 %>% # filter for the timeframe
  filter(Date >= "1979-10-01" & Date <= "2022-09-30") %>%
  #filter(temperature_mean >= -30 & temperature_mean <= 20) %>% # removing outliers   
  addWaterYear() %>% 
  mutate(daymonth = format(as.Date(Date), "%d-%m")) %>% 
  na.omit()

#adding water day using difftime (SUPER COOL. example from [this](https://stackoverflow.com/questions/48123049/create-day-index-based-on-water-year))

snotel_739_clean <- snotel_739_clean %>% 
  group_by(waterYear)%>% 
  mutate(waterDay = (as.integer(difftime(Date, ymd(paste0(waterYear - 1 ,'-09-30')), units = "days"))))
# Check for outliers

ggplot(snotel_739_clean, aes(x = Date, y = temperature_mean)) +
  geom_point() + #lwd = 2) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('Daily temperature (°C)') + 
  xlab('Date')

snotel_739_clean <- snotel_739_clean %>% 
  mutate(temp_diff = abs(temperature_min - temperature_max)) %>% 
  filter(temperature_mean > -40) %>% 
  filter(temperature_mean < 25)
ggplot(snotel_739_clean, aes(x = Date, y = temp_diff)) + 
  geom_point() + #lwd = 2) +
  theme_few() +
  #geom_smooth(method = "lm", se=FALSE) +
  ylab('Daily temperature varience (°C)') + 
  xlab('Date')

Per Steven’s advice: :If there are more than 15 missing days, then…remove that year”

# filtering for temperature anomalies
snotel_739_cull_count <- snotel_739_clean %>% 
  filter(temperature_min > -40) %>% 
  count(waterYear)

snotel_739_cull_count
## # A tibble: 36 x 2
## # Groups:   waterYear [36]
##    waterYear     n
##        <dbl> <int>
##  1      1987   345
##  2      1988   273
##  3      1989   363
##  4      1990   365
##  5      1991   365
##  6      1992   365
##  7      1993   342
##  8      1994   345
##  9      1995   362
## 10      1996   365
## # ... with 26 more rows
# filtering for too few observations in a year
snotel_739_cull_count_days <- snotel_739_clean %>% 
  group_by(waterYear) %>% 
  count(waterYear) %>% 
  filter(n < 350)

snotel_739_cull_count_days
## # A tibble: 6 x 2
## # Groups:   waterYear [6]
##   waterYear     n
##       <dbl> <int>
## 1      1987   345
## 2      1988   273
## 3      1993   343
## 4      1994   345
## 5      2016   320
## 6      2017   249

1987, 1988, 1993, 1994, 2016, 2017 need to be culled.

snotel_739_clean_culled <- snotel_739_clean %>% 
  filter(waterYear != "1987" & waterYear != "1988" & waterYear != "1993" & waterYear != "1994" & waterYear != "2016" & waterYear != "2017")# & waterYear != "1993" & waterYear != "1994" & waterYear != "2021" & waterYear != "2022") & waterYear != "2014") #%>% 
  #filter(temperature_mean > -49)

ggplot(snotel_739_clean_culled, aes(x = Date, y = temp_diff)) + 
  geom_point() + #lwd = 2) +
  theme_few() +
  #geom_smooth(method = "lm", se=FALSE) +
  ylab('Daily temperature varience (°C)') + 
  xlab('Date')

ggplot(snotel_739_clean_culled, aes(x = Date, y = temperature_mean)) + 
  geom_point() + #lwd = 2) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('Daily temperature (°C)') + 
  xlab('Date')

temp_739_xts <- xts(snotel_739_clean_culled$temperature_mean, order.by = snotel_739_clean_culled$Date)

dygraph(temp_739_xts) %>%
  dyAxis("y", label = "Daily mean temperature (°C)") 
snotel_739_clean_culled <- snotel_739_clean_culled %>% 
  filter(temperature_mean < 19.3)

temp_739_xts <- xts(snotel_739_clean_culled$temperature_mean, order.by = snotel_739_clean_culled$Date)

dygraph(temp_739_xts) %>%
  dyAxis("y", label = "Daily mean temperature (°C)") 

Scotch Creek 739

Morrisey 6/15/2004

snotel_739_adjusted <- snotel_739_clean_culled %>%
  mutate(temp_ad = if_else(Date < "2004-06-15", ((5.3*10^(-7))*(temperature_mean^(4))+(3.72*10^(-5))*(temperature_mean^(3))-(2.16*10^(-3))*(temperature_mean^(2))-(7.32*10^(-2))*(temperature_mean)+1.37)+temperature_mean, temperature_mean))

Non-corrected

739 Detrended

#using the clean culled df:

#average water year temperature

yearly_wy_aver_739 <- snotel_739_adjusted %>% 
  group_by(waterYear) %>% 
  mutate(aver_ann_temp = mean(temperature_mean))

#Average temperature by day for all water years:

daily_wy_aver_739 <- yearly_wy_aver_739 %>% 
  group_by(daymonth) %>% 
  mutate(aver_day_temp = mean(aver_ann_temp))

#average mean temperature by day for the period of record:

daily_wy_aver_739 <- daily_wy_aver_739 %>% 
  group_by(daymonth) %>% 
  mutate(all_ave_temp = mean(daily_wy_aver_739$aver_day_temp))

# try to show all years as means. 
daily_wy_aver2_739 <-daily_wy_aver_739 %>% 
  group_by(waterDay) %>%
  mutate(date_temp = mean(temperature_mean))
  

daily_wy_aver2_739$date_temp <- signif(daily_wy_aver2_739$date_temp,3) #reduce the sig figs


ggplot(daily_wy_aver2_739, aes(x = waterDay, y = date_temp))+
  geom_line(size= 0.7) +
  theme_few() +
  ylab('Average Daily temperature (°C)') + 
  xlab('Day of water year')

739 SD

standard_dev_739 <- daily_wy_aver_739 %>% 
  group_by(waterYear) %>% 
  mutate(residual = (all_ave_temp-aver_ann_temp)+temperature_mean-aver_day_temp) %>% 
  mutate(deviation = abs(residual-lag(residual)))

standard_dev_all_739 <- standard_dev_739 %>% 
  group_by(waterYear) %>% 
  mutate(nmbr = n())

standard_dev_all_739 <- standard_dev_all_739 %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)

standard_dev_all_739 %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1989 7.327097
1990 6.021389
1991 5.989983
1992 4.863013
1995 7.600315
1996 7.840086
1997 7.952598
1998 8.393336
1999 7.124567
2000 7.697346
2001 8.108824
2002 8.727256
2003 7.977395
2004 7.894210
2005 7.144352
2006 7.250093
2007 7.615681
2008 7.916198
2009 6.788880
2010 7.880288
2011 7.703849
2012 7.458561
2013 8.171355
2014 7.223604
2015 6.545241
2018 6.908918
2019 7.558347
2020 7.673725
2021 7.658883
2022 7.427996
ggplot(standard_dev_all_739, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Non-corrected standard deviation of SNOTEL 739 average temperatures for water years 2005-2021

MK & SS for 739 (non-corrected)

sd_mk_739 <- mk.test(standard_dev_all_739$sd_2)
print(sd_mk_739)
## 
##  Mann-Kendall trend test
## 
## data:  standard_dev_all_739$sd_2
## z = 0, n = 30, p-value = 1
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##            S         varS          tau 
## 1.000000e+00 3.141667e+03 2.298851e-03
sd_sens_739 <- sens.slope(standard_dev_all_739$sd_2)
print(sd_sens_739)
## 
##  Sen's slope
## 
## data:  standard_dev_all_739$sd_2
## z = 0, n = 30, p-value = 1
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.02559406  0.03474477
## sample estimates:
##  Sen's slope 
## 0.0005911373

Corrected

739 Detrended (corrected)

#using the clean culled df:
#average water year temperature
yearly_wy_aver_739_ad <- snotel_739_adjusted %>% 
  group_by(waterYear) %>% 
  mutate(aver_ann_temp_ad = mean(temp_ad))
#Average temperature by day for all water years:
daily_wy_aver_739_ad <- yearly_wy_aver_739_ad %>% 
  group_by(daymonth) %>% 
  mutate(aver_day_temp_ad = mean(aver_ann_temp_ad))
#average mean temperature by day for the period of record:
daily_wy_aver_739_ad <- daily_wy_aver_739_ad %>% 
  group_by(daymonth) %>% 
  mutate(all_ave_temp_ad = mean(daily_wy_aver_739_ad$aver_day_temp_ad))
# try to show all years as means. 
daily_wy_aver2_739_ad <-daily_wy_aver_739_ad %>% 
  group_by(waterDay) %>%
  mutate(date_temp_ad = mean(temp_ad))
  
daily_wy_aver2_739_ad$date_temp_ad <- signif(daily_wy_aver2_739_ad$date_temp_ad,3) #reduce the sig figs
ggplot(daily_wy_aver2_739_ad, aes(x = waterDay, y = date_temp_ad))+
  geom_line(size= 0.7) +
  theme_few() +
  ylab('Average Daily temperature (°C)') + 
  xlab('Day of water year')

739 SS (corrected)

standard_dev_739_ad <- daily_wy_aver_739_ad %>% 
  group_by(waterYear) %>% 
  #filter(waterYear >= 1987 & waterYear <= 2021) %>% 
  mutate(residual = (all_ave_temp_ad-aver_ann_temp_ad)+temp_ad-aver_day_temp_ad) %>% 
  mutate(deviation = abs(residual-lag(residual)))
standard_dev_all_739_ad <- standard_dev_739_ad %>% 
  group_by(waterYear) %>% 
  mutate(nmbr = n())
standard_dev_all_739_ad <- standard_dev_all_739_ad %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)
standard_dev_all_739_ad %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1989 6.882254
1990 5.641380
1991 5.682802
1992 4.573743
1995 7.029026
1996 7.246834
1997 7.374205
1998 7.773434
1999 6.583515
2000 7.110733
2001 7.493196
2002 8.076937
2003 7.362576
2004 7.247292
2005 7.144310
2006 7.250207
2007 7.615515
2008 7.916383
2009 6.789140
2010 7.880400
2011 7.703781
2012 7.458914
2013 8.171585
2014 7.223615
2015 6.545250
2018 6.908860
2019 7.558520
2020 7.674026
2021 7.658936
2022 7.428362
ggplot(standard_dev_all_739_ad, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Morrisey-corrected standard deviation of SNOTEL 739 average temperatures for water years 1986-2021

MK & SS 739 (corrected)

sd_mk_739_ad <- mk.test(standard_dev_all_739_ad$sd_2)
print(sd_mk_739_ad)
## 
##  Mann-Kendall trend test
## 
## data:  standard_dev_all_739_ad$sd_2
## z = 2.3907, n = 30, p-value = 0.01682
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##            S         varS          tau 
##  135.0000000 3141.6666667    0.3103448
sd_sens_739_ad <- sens.slope(standard_dev_all_739_ad$sd_2)
print(sd_sens_739_ad)
## 
##  Sen's slope
## 
## data:  standard_dev_all_739_ad$sd_2
## z = 2.3907, n = 30, p-value = 0.01682
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  0.00806300 0.05860595
## sample estimates:
## Sen's slope 
##  0.02802846

Summer and Winter SD NOT-CORRECTED

Summer

summer_standard_dev_all_739 <- standard_dev_739 %>%
  filter(waterDay >= 244 & waterDay <= 335) %>%
  group_by(waterYear) %>% 
  mutate(nmbr = n())

summer_standard_dev_all_739 <- summer_standard_dev_all_739 %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)

summer_standard_dev_all_739 %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1989 2.536063
1990 2.091777
1991 1.899421
1992 2.191209
1995 2.938309
1996 1.887456
1997 1.912590
1998 2.809296
1999 2.529949
2000 1.932726
2001 2.352198
2002 2.220673
2003 2.464625
2004 2.327233
2005 2.646323
2006 1.792276
2007 2.092948
2008 2.102311
2009 2.386216
2010 2.100594
2011 1.840326
2012 1.559146
2013 1.939526
2014 1.846238
2015 2.036347
2018 1.620029
2019 2.139991
2020 1.951129
2021 1.888555
2022 1.816675
ggplot(summer_standard_dev_all_739, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Non-corrected standard deviation of SNOTEL 739 average summer temperatures for water years 2005-2021

summer MK & SS for 739 (non-corrected)

summer_sd_mk_739 <- mk.test(summer_standard_dev_all_739$sd_2)
print(summer_sd_mk_739)
## 
##  Mann-Kendall trend test
## 
## data:  summer_standard_dev_all_739$sd_2
## z = -2.4621, n = 30, p-value = 0.01381
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##            S         varS          tau 
## -139.0000000 3141.6666667   -0.3195402
summer_sd_sens_739 <- sens.slope(summer_standard_dev_all_739$sd_2)
print(summer_sd_sens_739)
## 
##  Sen's slope
## 
## data:  summer_standard_dev_all_739$sd_2
## z = -2.4621, n = 30, p-value = 0.01381
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.034389289 -0.003903077
## sample estimates:
## Sen's slope 
## -0.01943234

Winter

winter_standard_dev_all_739 <- standard_dev_739 %>%
  filter(waterDay >= 32 & waterDay <= 182) %>%
  group_by(waterYear) %>% 
  mutate(nmbr = n())

winter_standard_dev_all_739 <- winter_standard_dev_all_739 %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)

winter_standard_dev_all_739 %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1989 5.526982
1990 4.286471
1991 4.806519
1992 3.671502
1995 4.428531
1996 4.403085
1997 4.558376
1998 4.420439
1999 4.103676
2000 4.520720
2001 3.763356
2002 4.869553
2003 3.918235
2004 5.273369
2005 3.826935
2006 4.277452
2007 4.857620
2008 5.240319
2009 4.089971
2010 4.127199
2011 5.058688
2012 3.660887
2013 5.142996
2014 3.958382
2015 4.114433
2018 3.906291
2019 3.878282
2020 4.288826
2021 4.058320
2022 4.212817
ggplot(winter_standard_dev_all_739, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Non-corrected standard deviation of SNOTEL 739 average winter temperatures for water years 2005-2021

winter MK & SS for 739 (non-corrected)

winter_sd_mk_739 <- mk.test(winter_standard_dev_all_739$sd_2)
print(winter_sd_mk_739)
## 
##  Mann-Kendall trend test
## 
## data:  winter_standard_dev_all_739$sd_2
## z = -1.2846, n = 30, p-value = 0.1989
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##            S         varS          tau 
##  -73.0000000 3141.6666667   -0.1678161
winter_sd_sens_739 <- sens.slope(winter_standard_dev_all_739$sd_2)
print(winter_sd_sens_739)
## 
##  Sen's slope
## 
## data:  winter_standard_dev_all_739$sd_2
## z = -1.2846, n = 30, p-value = 0.1989
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.03347603  0.01067222
## sample estimates:
## Sen's slope 
## -0.01498978

Summer and Winter SD CORRECTED

Summer

summer_standard_dev_all_739_ad <- standard_dev_739_ad %>% 
  filter(waterDay >= 244 & waterDay <= 335) %>%
  group_by(waterYear) %>% 
  mutate(nmbr = n())
summer_standard_dev_all_739_ad <- summer_standard_dev_all_739_ad %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)
summer_standard_dev_all_739_ad %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1989 2.287694
1990 1.897615
1991 1.733673
1992 2.002649
1995 2.637660
1996 1.689280
1997 1.716626
1998 2.522226
1999 2.276814
2000 1.730206
2001 2.111149
2002 1.988276
2003 2.206426
2004 2.200327
2005 2.645890
2006 1.791669
2007 2.092764
2008 2.102071
2009 2.385848
2010 2.100675
2011 1.839896
2012 1.558492
2013 1.939878
2014 1.845489
2015 2.036358
2018 1.619529
2019 2.139593
2020 1.950178
2021 1.888439
2022 1.816671
ggplot(summer_standard_dev_all_739_ad, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Morrisey-corrected standard deviation of SNOTEL 739 average summer temperatures for water years 1986-2021

summer MK & SS 739 (corrected)

summer_sd_mk_739_ad <- mk.test(summer_standard_dev_all_739_ad$sd_2)
print(summer_sd_mk_739_ad)
## 
##  Mann-Kendall trend test
## 
## data:  summer_standard_dev_all_739_ad$sd_2
## z = -1.1775, n = 30, p-value = 0.239
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##           S        varS         tau 
##  -67.000000 3141.666667   -0.154023
summer_sd_sens_739_ad <- sens.slope(summer_standard_dev_all_739_ad$sd_2)
print(summer_sd_sens_739_ad)
## 
##  Sen's slope
## 
## data:  summer_standard_dev_all_739_ad$sd_2
## z = -1.1775, n = 30, p-value = 0.239
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.019874143  0.005901278
## sample estimates:
##  Sen's slope 
## -0.007567534

Winter

winter_standard_dev_all_739_ad <- standard_dev_739_ad %>% 
  filter(waterDay >= 32 & waterDay <= 182) %>%
  group_by(waterYear) %>% 
  mutate(nmbr = n())
winter_standard_dev_all_739_ad <- winter_standard_dev_all_739_ad %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)
winter_standard_dev_all_739_ad %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1989 5.349986
1990 4.111286
1991 4.682872
1992 3.514678
1995 4.239937
1996 4.226770
1997 4.372688
1998 4.241526
1999 3.922109
2000 4.321534
2001 3.609996
2002 4.664023
2003 3.760080
2004 5.057360
2005 3.826730
2006 4.278107
2007 4.857019
2008 5.239709
2009 4.090550
2010 4.127290
2011 5.058421
2012 3.661139
2013 5.143336
2014 3.958876
2015 4.114007
2018 3.906290
2019 3.878351
2020 4.288406
2021 4.058565
2022 4.213592
ggplot(winter_standard_dev_all_739_ad, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Morrisey-corrected standard deviation of SNOTEL 739 average winter temperatures for water years 1986-2021

winter MK & SS 739 (corrected)

winter_sd_mk_739_ad <- mk.test(winter_standard_dev_all_739_ad$sd_2)
print(winter_sd_mk_739_ad)
## 
##  Mann-Kendall trend test
## 
## data:  winter_standard_dev_all_739_ad$sd_2
## z = -0.49955, n = 30, p-value = 0.6174
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##             S          varS           tau 
##  -29.00000000 3141.66666667   -0.06666667
winter_sd_sens_739_ad <- sens.slope(winter_standard_dev_all_739_ad$sd_2)
print(winter_sd_sens_739_ad)
## 
##  Sen's slope
## 
## data:  winter_standard_dev_all_739_ad$sd_2
## z = -0.49955, n = 30, p-value = 0.6174
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.02434186  0.01865529
## sample estimates:
##  Sen's slope 
## -0.005934895

Spring and Fall SD NOT-CORRECTED

Spring

spring_standard_dev_all_739 <- standard_dev_739 %>%
  filter(waterDay >= 183 & waterDay <= 243) %>%
  group_by(waterYear) %>% 
  mutate(nmbr = n())

spring_standard_dev_all_739 <- spring_standard_dev_all_739 %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)

spring_standard_dev_all_739 %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1989 2.534315
1990 2.422188
1991 3.413706
1992 2.525940
1995 3.055983
1996 4.381184
1997 4.679151
1998 4.289828
1999 4.274210
2000 4.042639
2001 4.308405
2002 3.338910
2003 4.428383
2004 3.124190
2005 3.818832
2006 3.304276
2007 3.223952
2008 3.664326
2009 4.118481
2010 4.185016
2011 3.480345
2012 3.281513
2013 3.708531
2014 4.010145
2015 2.607134
2018 3.326163
2019 2.687864
2020 3.282725
2021 2.940829
2022 3.840897
ggplot(spring_standard_dev_all_739, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Non-corrected standard deviation of SNOTEL 739 average spring temperatures for water years 2005-2021

spring MK & SS for 739 (non-corrected)

spring_sd_mk_739 <- mk.test(spring_standard_dev_all_739$sd_2)
print(spring_sd_mk_739)
## 
##  Mann-Kendall trend test
## 
## data:  spring_standard_dev_all_739$sd_2
## z = -0.6066, n = 30, p-value = 0.5441
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##             S          varS           tau 
##  -35.00000000 3141.66666667   -0.08045977
spring_sd_sens_739 <- sens.slope(spring_standard_dev_all_739$sd_2)
print(spring_sd_sens_739)
## 
##  Sen's slope
## 
## data:  spring_standard_dev_all_739$sd_2
## z = -0.6066, n = 30, p-value = 0.5441
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.04476144  0.02125699
## sample estimates:
## Sen's slope 
## -0.01222408

Fall

Fall is split each water year in the middle of the season. This analysis splits the fall season between the preceding water year and the subsequent water year.

fall_standard_dev_all_739 <- standard_dev_739 %>%
  filter(waterDay >= 336 | waterDay <= 31) %>% 
  group_by(waterYear) %>% 
  mutate(nmbr = n())

fall_standard_dev_all_739 <- fall_standard_dev_all_739 %>% 
  #group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)

fall_standard_dev_all_739 %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1989 2.474454
1990 3.370774
1991 2.431969
1992 2.771045
1995 4.672669
1996 3.723930
1997 5.370370
1998 5.272705
1999 3.441274
2000 3.747585
2001 3.809955
2002 3.351570
2003 3.860406
2004 3.135464
2005 3.930985
2006 2.720809
2007 4.271271
2008 3.127010
2009 3.109925
2010 4.880128
2011 3.557831
2012 3.882799
2013 3.999097
2014 4.543856
2015 2.860610
2018 3.172047
2019 4.260585
2020 4.933941
2021 3.783214
2022 4.300834
ggplot(fall_standard_dev_all_739, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Non-corrected standard deviation of SNOTEL 739 average fall temperatures for water years 2005-2021. Note that the season is split by the water year.

fall MK & SS for 739 (non-corrected)

fall_sd_mk_739 <- mk.test(fall_standard_dev_all_739$sd_2)
print(fall_sd_mk_739)
## 
##  Mann-Kendall trend test
## 
## data:  fall_standard_dev_all_739$sd_2
## z = 1.57, n = 30, p-value = 0.1164
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##            S         varS          tau 
##   89.0000000 3141.6666667    0.2045977
fall_sd_sens_739 <- sens.slope(fall_standard_dev_all_739$sd_2)
print(fall_sd_sens_739)
## 
##  Sen's slope
## 
## data:  fall_standard_dev_all_739$sd_2
## z = 1.57, n = 30, p-value = 0.1164
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.01055512  0.06033822
## sample estimates:
## Sen's slope 
##  0.02583578

Spring and Fall SD CORRECTED

Spring

spring_standard_dev_all_739_ad <- standard_dev_739_ad %>% 
  filter(waterDay >= 183 & waterDay <= 243) %>%
  group_by(waterYear) %>% 
  mutate(nmbr = n())
spring_standard_dev_all_739_ad <- spring_standard_dev_all_739_ad %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)
spring_standard_dev_all_739_ad %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1989 2.325437
1990 2.220212
1991 3.176111
1992 2.331306
1995 2.818639
1996 4.003866
1997 4.327934
1998 3.944586
1999 3.949519
2000 3.677705
2001 3.940477
2002 3.026923
2003 4.044159
2004 2.849843
2005 3.819051
2006 3.304579
2007 3.225296
2008 3.664855
2009 4.119034
2010 4.184440
2011 3.479592
2012 3.281635
2013 3.709534
2014 4.010097
2015 2.607558
2018 3.327643
2019 2.688390
2020 3.283596
2021 2.940897
2022 3.841650
ggplot(spring_standard_dev_all_739_ad, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Morrisey-corrected standard deviation of SNOTEL 739 average spring temperatures for water years 1986-2021

spring MK & SS 739 (corrected)

spring_sd_mk_739_ad <- mk.test(spring_standard_dev_all_739_ad$sd_2)
print(spring_sd_mk_739_ad)
## 
##  Mann-Kendall trend test
## 
## data:  spring_standard_dev_all_739_ad$sd_2
## z = 0.42818, n = 30, p-value = 0.6685
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##            S         varS          tau 
## 2.500000e+01 3.141667e+03 5.747126e-02
spring_sd_sens_739_ad <- sens.slope(spring_standard_dev_all_739_ad$sd_2)
print(spring_sd_sens_739_ad)
## 
##  Sen's slope
## 
## data:  spring_standard_dev_all_739_ad$sd_2
## z = 0.42818, n = 30, p-value = 0.6685
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.02797315  0.03967460
## sample estimates:
## Sen's slope 
## 0.005094047

Fall

fall_standard_dev_all_739_ad <- standard_dev_739_ad %>% 
  filter(waterDay >= 336 | waterDay <= 31) %>%
  group_by(waterYear) %>% 
  mutate(nmbr = n())
fall_standard_dev_all_739_ad <- fall_standard_dev_all_739_ad %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)
fall_standard_dev_all_739_ad %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1989 2.243171
1990 3.107931
1991 2.229321
1992 2.577272
1995 4.247735
1996 3.392103
1997 4.929702
1998 4.824411
1999 3.140515
2000 3.403744
2001 3.467760
2002 3.039510
2003 3.523038
2004 2.835881
2005 3.930977
2006 2.720457
2007 4.271042
2008 3.127410
2009 3.110794
2010 4.881196
2011 3.558549
2012 3.882993
2013 3.998495
2014 4.543608
2015 2.861162
2018 3.172432
2019 4.261519
2020 4.934336
2021 3.782732
2022 4.301190
ggplot(fall_standard_dev_all_739_ad, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Morrisey-corrected standard deviation of SNOTEL 739 average fall temperatures for water years 1986-2021. Note that the fall season is split by the water year.

fall MK & SS 739 (corrected)

fall_sd_mk_739_ad <- mk.test(fall_standard_dev_all_739_ad$sd_2)
print(fall_sd_mk_739_ad)
## 
##  Mann-Kendall trend test
## 
## data:  fall_standard_dev_all_739_ad$sd_2
## z = 2.4264, n = 30, p-value = 0.01525
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##            S         varS          tau 
##  137.0000000 3141.6666667    0.3149425
fall_sd_sens_739_ad <- sens.slope(fall_standard_dev_all_739_ad$sd_2)
print(fall_sd_sens_739_ad)
## 
##  Sen's slope
## 
## data:  fall_standard_dev_all_739_ad$sd_2
## z = 2.4264, n = 30, p-value = 0.01525
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  0.004732057 0.072882314
## sample estimates:
## Sen's slope 
##  0.04140076

Slumgullion 762

Morrisey 6/26/2006

snotel_762 <- SNOTEL_san_juan_Area %>% 
  filter(site_id == "762")
#str(snotel_762) # check the date, usually a character.  

snotel_762$Date <- as.Date(snotel_762$date) #change date from character to date format, capitalize to work with Water year functon from NWIS.

#THIS WILL CHANGE FOR EACH STATION
snotel_762_clean <- snotel_762 %>% # filter for the timeframe
  filter(Date >= "1979-10-01" & Date <= "2022-09-30") %>%
  #filter(temperature_mean >= -30 & temperature_mean <= 20) %>% # removing outliers   
  addWaterYear() %>% 
  mutate(daymonth = format(as.Date(Date), "%d-%m")) %>% 
  na.omit()

#adding water day using difftime (SUPER COOL. example from [this](https://stackoverflow.com/questions/48123049/create-day-index-based-on-water-year))

snotel_762_clean <- snotel_762_clean %>% 
  group_by(waterYear)%>% 
  mutate(waterDay = (as.integer(difftime(Date, ymd(paste0(waterYear - 1 ,'-09-30')), units = "days"))))
# Check for outliers

ggplot(snotel_762_clean, aes(x = Date, y = temperature_mean)) +
  geom_point() + #lwd = 2) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('Daily temperature (°C)') + 
  xlab('Date')

snotel_762_clean <- snotel_762_clean %>% 
  mutate(temp_diff = abs(temperature_min - temperature_max)) %>% 
  filter(temperature_mean > -40) %>% 
  filter(temperature_mean < 25)
ggplot(snotel_762_clean, aes(x = Date, y = temp_diff)) + 
  geom_point() + #lwd = 2) +
  theme_few() +
  #geom_smooth(method = "lm", se=FALSE) +
  ylab('Daily temperature varience (°C)') + 
  xlab('Date')

Per Steven’s advice: :If there are more than 15 missing days, then…remove that year”

# filtering for temperature anomalies
#snotel_762_cull_count <- snotel_762_clean %>% 
#  filter(temperature_min > -40) %>% 
#  count(waterYear)

#snotel_762_cull_count

# filtering for too few observations in a year
snotel_762_cull_count_days <- snotel_762_clean %>% 
  group_by(waterYear) %>% 
  count(waterYear) %>% 
  filter(n < 350)

snotel_762_cull_count_days
## # A tibble: 5 x 2
## # Groups:   waterYear [5]
##   waterYear     n
##       <dbl> <int>
## 1      1980    43
## 2      1982     1
## 3      1983   319
## 4      1994   331
## 5      2003   337

1980, 1982, 1994, 2003 need to be culled. 1995 maximums are less than the minimums.

snotel_762_clean_culled <- snotel_762_clean %>% 
  filter(waterYear != "1980" & waterYear != "1981" & waterYear != "1982" & waterYear != "1983" & waterYear != "1994" & waterYear != "1995" & waterYear != "2003")# & waterYear != "2017" & waterYear != "1993" & waterYear != "1994" & waterYear != "2021" & waterYear != "2022") & waterYear != "2014") #%>% 
  #filter(temperature_mean > -49)

ggplot(snotel_762_clean_culled, aes(x = Date, y = temp_diff)) + 
  geom_point() + #lwd = 2) +
  theme_few() +
  #geom_smooth(method = "lm", se=FALSE) +
  ylab('Daily temperature varience (°C)') + 
  xlab('Date')

ggplot(snotel_762_clean_culled, aes(x = Date, y = temperature_mean)) + 
  geom_point() + #lwd = 2) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('Daily temperature (°C)') + 
  xlab('Date')

temp_762_xts <- xts(snotel_762_clean_culled$temperature_mean, order.by = snotel_762_clean_culled$Date)

dygraph(temp_762_xts) %>%
  dyAxis("y", label = "Daily mean temperature (°C)") 
#snotel_762_clean_culled <- snotel_762_clean_culled %>% 
#  filter(temperature_mean < 19.3)

temp_762_xts <- xts(snotel_762_clean_culled$temperature_mean, order.by = snotel_762_clean_culled$Date)

dygraph(temp_762_xts) %>%
  dyAxis("y", label = "Daily mean temperature (°C)") 

Slumgullion 762

Morrisey 6/26/2006

snotel_762_adjusted <- snotel_762_clean_culled %>%
  mutate(temp_ad = if_else(Date < "2006-06-26", ((5.3*10^(-7))*(temperature_mean^(4))+(3.72*10^(-5))*(temperature_mean^(3))-(2.16*10^(-3))*(temperature_mean^(2))-(7.32*10^(-2))*(temperature_mean)+1.37)+temperature_mean, temperature_mean))

Non-corrected

762 Detrended

#using the clean culled df:

#average water year temperature

yearly_wy_aver_762 <- snotel_762_adjusted %>% 
  group_by(waterYear) %>% 
  mutate(aver_ann_temp = mean(temperature_mean))

#Average temperature by day for all water years:

daily_wy_aver_762 <- yearly_wy_aver_762 %>% 
  group_by(daymonth) %>% 
  mutate(aver_day_temp = mean(aver_ann_temp))

#average mean temperature by day for the period of record:

daily_wy_aver_762 <- daily_wy_aver_762 %>% 
  group_by(daymonth) %>% 
  mutate(all_ave_temp = mean(daily_wy_aver_762$aver_day_temp))

# try to show all years as means. 
daily_wy_aver2_762 <-daily_wy_aver_762 %>% 
  group_by(waterDay) %>%
  mutate(date_temp = mean(temperature_mean))
  

daily_wy_aver2_762$date_temp <- signif(daily_wy_aver2_762$date_temp,3) #reduce the sig figs


ggplot(daily_wy_aver2_762, aes(x = waterDay, y = date_temp))+
  geom_line(size= 0.7) +
  theme_few() +
  ylab('Average Daily temperature (°C)') + 
  xlab('Day of water year')

762 SD

standard_dev_762 <- daily_wy_aver_762 %>% 
  group_by(waterYear) %>% 
  mutate(residual = (all_ave_temp-aver_ann_temp)+temperature_mean-aver_day_temp) %>% 
  mutate(deviation = abs(residual-lag(residual)))

standard_dev_all_762 <- standard_dev_762 %>% 
  group_by(waterYear) %>% 
  mutate(nmbr = n())

standard_dev_all_762 <- standard_dev_all_762 %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)

standard_dev_all_762 %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1984 8.474614
1985 8.395416
1986 7.224771
1987 8.036169
1988 8.470217
1989 8.556810
1990 8.104917
1991 8.129177
1992 7.378858
1993 7.881362
1996 8.151725
1997 8.002402
1998 8.492764
1999 7.140044
2000 7.859908
2001 8.456394
2002 8.777834
2004 8.172096
2005 8.157803
2006 8.479381
2007 7.832136
2008 8.378519
2009 7.328609
2010 8.218219
2011 8.186856
2012 7.846460
2013 8.493891
2014 7.772861
2015 7.080609
2016 7.803357
2017 7.532567
2018 7.423620
2019 8.010211
2020 8.142119
2021 8.245368
2022 7.614681
ggplot(standard_dev_all_762, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Non-corrected standard deviation of SNOTEL 762 average temperatures for water years 2005-2021

MK & SS for 762 (non-corrected)

sd_mk_762 <- mk.test(standard_dev_all_762$sd_2)
print(sd_mk_762)
## 
##  Mann-Kendall trend test
## 
## data:  standard_dev_all_762$sd_2
## z = -1.4574, n = 36, p-value = 0.145
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##            S         varS          tau 
## -108.0000000 5390.0000000   -0.1714286
sd_sens_762 <- sens.slope(standard_dev_all_762$sd_2)
print(sd_sens_762)
## 
##  Sen's slope
## 
## data:  standard_dev_all_762$sd_2
## z = -1.4574, n = 36, p-value = 0.145
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.024958596  0.002910121
## sample estimates:
## Sen's slope 
## -0.01112266

Corrected

762 Detrended (corrected)

#using the clean culled df:
#average water year temperature
yearly_wy_aver_762_ad <- snotel_762_adjusted %>% 
  group_by(waterYear) %>% 
  mutate(aver_ann_temp_ad = mean(temp_ad))
#Average temperature by day for all water years:
daily_wy_aver_762_ad <- yearly_wy_aver_762_ad %>% 
  group_by(daymonth) %>% 
  mutate(aver_day_temp_ad = mean(aver_ann_temp_ad))
#average mean temperature by day for the period of record:
daily_wy_aver_762_ad <- daily_wy_aver_762_ad %>% 
  group_by(daymonth) %>% 
  mutate(all_ave_temp_ad = mean(daily_wy_aver_762_ad$aver_day_temp_ad))
# try to show all years as means. 
daily_wy_aver2_762_ad <-daily_wy_aver_762_ad %>% 
  group_by(waterDay) %>%
  mutate(date_temp_ad = mean(temp_ad))
  
daily_wy_aver2_762_ad$date_temp_ad <- signif(daily_wy_aver2_762_ad$date_temp_ad,3) #reduce the sig figs
ggplot(daily_wy_aver2_762_ad, aes(x = waterDay, y = date_temp_ad))+
  geom_line(size= 0.7) +
  theme_few() +
  ylab('Average Daily temperature (°C)') + 
  xlab('Day of water year')

762 SS (corrected)

standard_dev_762_ad <- daily_wy_aver_762_ad %>% 
  group_by(waterYear) %>% 
  #filter(waterYear >= 1987 & waterYear <= 2021) %>% 
  mutate(residual = (all_ave_temp_ad-aver_ann_temp_ad)+temp_ad-aver_day_temp_ad) %>% 
  mutate(deviation = abs(residual-lag(residual)))
standard_dev_all_762_ad <- standard_dev_762_ad %>% 
  group_by(waterYear) %>% 
  mutate(nmbr = n())
standard_dev_all_762_ad <- standard_dev_all_762_ad %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)
standard_dev_all_762_ad %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1984 7.970791
1985 7.888311
1986 6.764665
1987 7.528970
1988 7.965877
1989 8.053090
1990 7.604786
1991 7.665906
1992 6.904408
1993 7.400370
1996 7.629529
1997 7.511155
1998 7.956453
1999 6.688385
2000 7.353371
2001 7.919104
2002 8.206929
2004 7.685091
2005 7.619040
2006 7.823927
2007 7.831876
2008 8.379138
2009 7.329078
2010 8.218734
2011 8.187217
2012 7.846411
2013 8.493922
2014 7.773398
2015 7.081459
2016 7.804132
2017 7.532344
2018 7.424275
2019 8.010639
2020 8.142599
2021 8.245690
2022 7.615524
ggplot(standard_dev_all_762_ad, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Morrisey-corrected standard deviation of SNOTEL 762 average temperatures for water years 1986-2021

MK & SS 762 (corrected)

sd_mk_762_ad <- mk.test(standard_dev_all_762_ad$sd_2)
print(sd_mk_762_ad)
## 
##  Mann-Kendall trend test
## 
## data:  standard_dev_all_762_ad$sd_2
## z = 1.2123, n = 36, p-value = 0.2254
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##            S         varS          tau 
##   90.0000000 5390.0000000    0.1428571
sd_sens_762_ad <- sens.slope(standard_dev_all_762_ad$sd_2)
print(sd_sens_762_ad)
## 
##  Sen's slope
## 
## data:  standard_dev_all_762_ad$sd_2
## z = 1.2123, n = 36, p-value = 0.2254
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.00495755  0.02329061
## sample estimates:
## Sen's slope 
## 0.009103679

Summer and Winter SD NOT-CORRECTED

Summer

summer_standard_dev_all_762 <- standard_dev_762 %>%
  filter(waterDay >= 244 & waterDay <= 335) %>%
  group_by(waterYear) %>% 
  mutate(nmbr = n())

summer_standard_dev_all_762 <- summer_standard_dev_all_762 %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)

summer_standard_dev_all_762 %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1984 2.822167
1985 2.555079
1986 2.456898
1987 2.326799
1988 2.500087
1989 3.281463
1990 2.649819
1991 2.481917
1992 2.963695
1993 2.790144
1996 2.378361
1997 2.358193
1998 3.185997
1999 2.475766
2000 1.869817
2001 2.644390
2002 2.439828
2004 2.563353
2005 3.421058
2006 2.194534
2007 2.598497
2008 2.415739
2009 2.925849
2010 2.356057
2011 1.997263
2012 1.775514
2013 2.046112
2014 2.092032
2015 2.375980
2016 2.597941
2017 1.879397
2018 1.844924
2019 2.569473
2020 2.556016
2021 2.555837
2022 2.102396
ggplot(summer_standard_dev_all_762, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Non-corrected standard deviation of SNOTEL 762 average summer temperatures for water years 2005-2021

summer MK & SS for 762 (non-corrected)

summer_sd_mk_762 <- mk.test(summer_standard_dev_all_762$sd_2)
print(summer_sd_mk_762)
## 
##  Mann-Kendall trend test
## 
## data:  summer_standard_dev_all_762$sd_2
## z = -2.3019, n = 36, p-value = 0.02134
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##            S         varS          tau 
## -170.0000000 5390.0000000   -0.2698413
summer_sd_sens_762 <- sens.slope(summer_standard_dev_all_762$sd_2)
print(summer_sd_sens_762)
## 
##  Sen's slope
## 
## data:  summer_standard_dev_all_762$sd_2
## z = -2.3019, n = 36, p-value = 0.02134
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.025908824 -0.002255574
## sample estimates:
## Sen's slope 
##  -0.0135962

Winter

winter_standard_dev_all_762 <- standard_dev_762 %>%
  filter(waterDay >= 32 & waterDay <= 182) %>%
  group_by(waterYear) %>% 
  mutate(nmbr = n())

winter_standard_dev_all_762 <- winter_standard_dev_all_762 %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)

winter_standard_dev_all_762 %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1984 4.995368
1985 4.776362
1986 4.673415
1987 4.214252
1988 4.925869
1989 5.787831
1990 5.030413
1991 4.990405
1992 3.600871
1993 3.860851
1996 4.853103
1997 5.005292
1998 4.309774
1999 4.363109
2000 5.106424
2001 4.007137
2002 5.049274
2004 5.401251
2005 4.115976
2006 4.838876
2007 5.203133
2008 5.549026
2009 4.564164
2010 4.542645
2011 5.336582
2012 4.358678
2013 5.680888
2014 4.319649
2015 4.719867
2016 4.854215
2017 5.253700
2018 4.335060
2019 4.067880
2020 4.554385
2021 4.535441
2022 4.856251
ggplot(winter_standard_dev_all_762, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Non-corrected standard deviation of SNOTEL 762 average winter temperatures for water years 2005-2021

winter MK & SS for 762 (non-corrected)

winter_sd_mk_762 <- mk.test(winter_standard_dev_all_762$sd_2)
print(winter_sd_mk_762)
## 
##  Mann-Kendall trend test
## 
## data:  winter_standard_dev_all_762$sd_2
## z = -0.040863, n = 36, p-value = 0.9674
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##             S          varS           tau 
## -4.000000e+00  5.390000e+03 -6.349206e-03
winter_sd_sens_762 <- sens.slope(winter_standard_dev_all_762$sd_2)
print(winter_sd_sens_762)
## 
##  Sen's slope
## 
## data:  winter_standard_dev_all_762$sd_2
## z = -0.040863, n = 36, p-value = 0.9674
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.01894413  0.02022456
## sample estimates:
##  Sen's slope 
## -0.000681984

Summer and Winter SD CORRECTED

Summer

summer_standard_dev_all_762_ad <- standard_dev_762_ad %>% 
  filter(waterDay >= 244 & waterDay <= 335) %>%
  group_by(waterYear) %>% 
  mutate(nmbr = n())
summer_standard_dev_all_762_ad <- summer_standard_dev_all_762_ad %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)
summer_standard_dev_all_762_ad %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1984 2.557710
1985 2.300170
1986 2.215330
1987 2.094745
1988 2.264840
1989 2.952743
1990 2.389207
1991 2.244600
1992 2.680413
1993 2.530155
1996 2.140008
1997 2.129328
1998 2.878370
1999 2.244239
2000 1.680367
2001 2.391753
2002 2.192942
2004 2.311148
2005 3.087189
2006 2.095769
2007 2.597803
2008 2.416464
2009 2.927464
2010 2.358119
2011 1.998743
2012 1.774917
2013 2.045463
2014 2.095539
2015 2.376063
2016 2.599228
2017 1.878151
2018 1.846389
2019 2.572313
2020 2.556578
2021 2.556287
2022 2.107440
ggplot(summer_standard_dev_all_762_ad, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Morrisey-corrected standard deviation of SNOTEL 762 average summer temperatures for water years 1986-2021

summer MK & SS 762 (corrected)

summer_sd_mk_762_ad <- mk.test(summer_standard_dev_all_762_ad$sd_2)
print(summer_sd_mk_762_ad)
## 
##  Mann-Kendall trend test
## 
## data:  summer_standard_dev_all_762_ad$sd_2
## z = -0.77639, n = 36, p-value = 0.4375
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##             S          varS           tau 
##  -58.00000000 5390.00000000   -0.09206349
summer_sd_sens_762_ad <- sens.slope(summer_standard_dev_all_762_ad$sd_2)
print(summer_sd_sens_762_ad)
## 
##  Sen's slope
## 
## data:  summer_standard_dev_all_762_ad$sd_2
## z = -0.77639, n = 36, p-value = 0.4375
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.01464010  0.00776112
## sample estimates:
##  Sen's slope 
## -0.004782858

Winter

winter_standard_dev_all_762_ad <- standard_dev_762_ad %>% 
  filter(waterDay >= 32 & waterDay <= 182) %>%
  group_by(waterYear) %>% 
  mutate(nmbr = n())
winter_standard_dev_all_762_ad <- winter_standard_dev_all_762_ad %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)
winter_standard_dev_all_762_ad %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1984 4.887027
1985 4.720205
1986 4.524947
1987 4.099691
1988 4.817354
1989 5.629118
1990 4.889271
1991 4.904495
1992 3.496221
1993 3.767984
1996 4.729201
1997 4.843802
1998 4.197520
1999 4.230043
2000 4.928233
2001 3.915699
2002 4.894103
2004 5.256656
2005 4.014931
2006 4.718241
2007 5.202411
2008 5.548451
2009 4.564190
2010 4.542164
2011 5.336551
2012 4.358113
2013 5.680945
2014 4.320050
2015 4.719525
2016 4.853884
2017 5.252630
2018 4.334773
2019 4.067965
2020 4.553878
2021 4.535578
2022 4.855907
ggplot(winter_standard_dev_all_762_ad, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Morrisey-corrected standard deviation of SNOTEL 762 average winter temperatures for water years 1986-2021

winter MK & SS 762 (corrected)

winter_sd_mk_762_ad <- mk.test(winter_standard_dev_all_762_ad$sd_2)
print(winter_sd_mk_762_ad)
## 
##  Mann-Kendall trend test
## 
## data:  winter_standard_dev_all_762_ad$sd_2
## z = 0.28604, n = 36, p-value = 0.7748
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##            S         varS          tau 
## 2.200000e+01 5.390000e+03 3.492063e-02
winter_sd_sens_762_ad <- sens.slope(winter_standard_dev_all_762_ad$sd_2)
print(winter_sd_sens_762_ad)
## 
##  Sen's slope
## 
## data:  winter_standard_dev_all_762_ad$sd_2
## z = 0.28604, n = 36, p-value = 0.7748
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.01448371  0.02461905
## sample estimates:
## Sen's slope 
## 0.001085455

Spring and Fall SD NOT-CORRECTED

Spring

spring_standard_dev_all_762 <- standard_dev_762 %>%
  filter(waterDay >= 183 & waterDay <= 243) %>%
  group_by(waterYear) %>% 
  mutate(nmbr = n())

spring_standard_dev_all_762 <- spring_standard_dev_all_762 %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)

spring_standard_dev_all_762 %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1984 6.293642
1985 3.376987
1986 3.904899
1987 3.622946
1988 4.649570
1989 4.215024
1990 3.054081
1991 4.800625
1992 3.182490
1993 4.417147
1996 5.216086
1997 5.226215
1998 4.970444
1999 5.021742
2000 4.749483
2001 4.740461
2002 3.595776
2004 4.025210
2005 4.671197
2006 4.066206
2007 4.037772
2008 4.583993
2009 4.744634
2010 4.745712
2011 4.372189
2012 3.943941
2013 4.435971
2014 4.940625
2015 3.046816
2016 3.720601
2017 4.258219
2018 4.721173
2019 3.405028
2020 4.622457
2021 3.908404
2022 4.975324
ggplot(spring_standard_dev_all_762, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Non-corrected standard deviation of SNOTEL 762 average spring temperatures for water years 2005-2021

spring MK & SS for 762 (non-corrected)

spring_sd_mk_762 <- mk.test(spring_standard_dev_all_762$sd_2)
print(spring_sd_mk_762)
## 
##  Mann-Kendall trend test
## 
## data:  spring_standard_dev_all_762$sd_2
## z = -0.31328, n = 36, p-value = 0.7541
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##             S          varS           tau 
##  -24.00000000 5390.00000000   -0.03809524
spring_sd_sens_762 <- sens.slope(spring_standard_dev_all_762$sd_2)
print(spring_sd_sens_762)
## 
##  Sen's slope
## 
## data:  spring_standard_dev_all_762$sd_2
## z = -0.31328, n = 36, p-value = 0.7541
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.02940326  0.02204466
## sample estimates:
##  Sen's slope 
## -0.003158335

Fall

Fall is split each water year in the middle of the season. This analysis splits the fall season between the preceding water year and the subsequent water year.

fall_standard_dev_all_762 <- standard_dev_762 %>%
  filter(waterDay >= 336 | waterDay <= 31) %>% 
  group_by(waterYear) %>% 
  mutate(nmbr = n())

fall_standard_dev_all_762 <- fall_standard_dev_all_762 %>% 
  #group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)

fall_standard_dev_all_762 %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1984 3.493684
1985 5.283356
1986 3.118421
1987 3.696418
1988 3.398064
1989 5.908081
1990 5.453874
1991 3.708992
1992 4.813630
1993 3.701088
1996 4.423749
1997 5.894003
1998 5.468747
1999 4.071904
2000 3.978714
2001 4.702043
2002 3.675178
2004 3.671120
2005 4.689549
2006 3.872877
2007 4.767301
2008 3.853324
2009 3.841105
2010 6.004570
2011 4.221392
2012 4.291658
2013 4.289123
2014 5.583659
2015 3.380260
2016 3.595166
2017 3.497520
2018 3.815477
2019 4.983657
2020 6.284256
2021 4.419952
2022 5.217303
ggplot(fall_standard_dev_all_762, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Non-corrected standard deviation of SNOTEL 762 average fall temperatures for water years 2005-2021. Note that the season is split by the water year.

fall MK & SS for 762 (non-corrected)

fall_sd_mk_762 <- mk.test(fall_standard_dev_all_762$sd_2)
print(fall_sd_mk_762)
## 
##  Mann-Kendall trend test
## 
## data:  fall_standard_dev_all_762$sd_2
## z = 0.72191, n = 36, p-value = 0.4704
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##            S         varS          tau 
## 5.400000e+01 5.390000e+03 8.571429e-02
fall_sd_sens_762 <- sens.slope(fall_standard_dev_all_762$sd_2)
print(fall_sd_sens_762)
## 
##  Sen's slope
## 
## data:  fall_standard_dev_all_762$sd_2
## z = 0.72191, n = 36, p-value = 0.4704
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.0156539  0.0361342
## sample estimates:
## Sen's slope 
##  0.01144673

Spring and Fall SD CORRECTED

Spring

spring_standard_dev_all_762_ad <- standard_dev_762_ad %>% 
  filter(waterDay >= 183 & waterDay <= 243) %>%
  group_by(waterYear) %>% 
  mutate(nmbr = n())
spring_standard_dev_all_762_ad <- spring_standard_dev_all_762_ad %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)
spring_standard_dev_all_762_ad %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1984 5.869220
1985 3.124422
1986 3.634935
1987 3.375683
1988 4.329026
1989 3.896392
1990 2.830216
1991 4.517708
1992 2.943528
1993 4.119153
1996 4.848620
1997 4.916563
1998 4.645744
1999 4.724399
2000 4.385474
2001 4.401546
2002 3.298255
2004 3.731160
2005 4.319506
2006 3.755662
2007 4.037341
2008 4.584732
2009 4.745240
2010 4.745380
2011 4.372905
2012 3.945133
2013 4.436212
2014 4.941890
2015 3.046930
2016 3.722295
2017 4.259924
2018 4.721620
2019 3.405534
2020 4.622333
2021 3.909207
2022 4.975032
ggplot(spring_standard_dev_all_762_ad, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Morrisey-corrected standard deviation of SNOTEL 762 average spring temperatures for water years 1986-2021

spring MK & SS 762 (corrected)

spring_sd_mk_762_ad <- mk.test(spring_standard_dev_all_762_ad$sd_2)
print(spring_sd_mk_762_ad)
## 
##  Mann-Kendall trend test
## 
## data:  spring_standard_dev_all_762_ad$sd_2
## z = 1.0216, n = 36, p-value = 0.307
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##            S         varS          tau 
##   76.0000000 5390.0000000    0.1206349
spring_sd_sens_762_ad <- sens.slope(spring_standard_dev_all_762_ad$sd_2)
print(spring_sd_sens_762_ad)
## 
##  Sen's slope
## 
## data:  spring_standard_dev_all_762_ad$sd_2
## z = 1.0216, n = 36, p-value = 0.307
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.01230473  0.03595467
## sample estimates:
## Sen's slope 
##  0.01093288

Fall

fall_standard_dev_all_762_ad <- standard_dev_762_ad %>% 
  filter(waterDay >= 336 | waterDay <= 31) %>%
  group_by(waterYear) %>% 
  mutate(nmbr = n())
fall_standard_dev_all_762_ad <- fall_standard_dev_all_762_ad %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)
fall_standard_dev_all_762_ad %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1984 3.192440
1985 4.939515
1986 2.870144
1987 3.426910
1988 3.108918
1989 5.559384
1990 5.040485
1991 3.427324
1992 4.499505
1993 3.404072
1996 4.086192
1997 5.500529
1998 5.063775
1999 3.761700
2000 3.649520
2001 4.326481
2002 3.374325
2004 3.364130
2005 4.340138
2006 3.402874
2007 4.765615
2008 3.855983
2009 3.841342
2010 6.006744
2011 4.220448
2012 4.288858
2013 4.286237
2014 5.582345
2015 3.384865
2016 3.593127
2017 3.493141
2018 3.817113
2019 4.981973
2020 6.284496
2021 4.417454
2022 5.217755
ggplot(fall_standard_dev_all_762_ad, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Morrisey-corrected standard deviation of SNOTEL 762 average fall temperatures for water years 1986-2021. Note that the fall season is split by the water year.

fall MK & SS 762 (corrected)

fall_sd_mk_762_ad <- mk.test(fall_standard_dev_all_762_ad$sd_2)
print(fall_sd_mk_762_ad)
## 
##  Mann-Kendall trend test
## 
## data:  fall_standard_dev_all_762_ad$sd_2
## z = 1.6754, n = 36, p-value = 0.09386
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##            S         varS          tau 
##  124.0000000 5390.0000000    0.1968254
fall_sd_sens_762_ad <- sens.slope(fall_standard_dev_all_762_ad$sd_2)
print(fall_sd_sens_762_ad)
## 
##  Sen's slope
## 
## data:  fall_standard_dev_all_762_ad$sd_2
## z = 1.6754, n = 36, p-value = 0.09386
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.003155808  0.051624532
## sample estimates:
## Sen's slope 
##  0.02221286

Spud Mountain 780

Morrisey 6/28/2004

snotel_780 <- SNOTEL_san_juan_Area %>% 
  filter(site_id == "780")
#str(snotel_780) # check the date, usually a character.  

snotel_780$Date <- as.Date(snotel_780$date) #change date from character to date format, capitalize to work with Water year functon from NWIS.

#THIS WILL CHANGE FOR EACH STATION
snotel_780_clean <- snotel_780 %>% # filter for the timeframe
  filter(Date >= "1979-10-01" & Date <= "2022-09-30") %>%
  #filter(temperature_mean >= -30 & temperature_mean <= 20) %>% # removing outliers   
  addWaterYear() %>% 
  mutate(daymonth = format(as.Date(Date), "%d-%m")) %>% 
  na.omit()

#adding water day using difftime (SUPER COOL. example from [this](https://stackoverflow.com/questions/48123049/create-day-index-based-on-water-year))

snotel_780_clean <- snotel_780_clean %>% 
  group_by(waterYear)%>% 
  mutate(waterDay = (as.integer(difftime(Date, ymd(paste0(waterYear - 1 ,'-09-30')), units = "days"))))
# Check for outliers

ggplot(snotel_780_clean, aes(x = Date, y = temperature_mean)) +
  geom_point() + #lwd = 2) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('Daily temperature (°C)') + 
  xlab('Date')

snotel_780_clean <- snotel_780_clean %>% 
  mutate(temp_diff = abs(temperature_min - temperature_max)) %>% 
  filter(temperature_mean > -40) %>% 
  filter(temperature_mean < 25)
ggplot(snotel_780_clean, aes(x = Date, y = temp_diff)) + 
  geom_point() + #lwd = 2) +
  theme_few() +
  #geom_smooth(method = "lm", se=FALSE) +
  ylab('Daily temperature varience (°C)') + 
  xlab('Date')

Per Steven’s advice: :If there are more than 15 missing days, then…remove that year”

# filtering for temperature anomalies
#snotel_780_cull_count <- snotel_780_clean %>% 
#  filter(temperature_min > -40) %>% 
#  count(waterYear)

#snotel_780_cull_count

# filtering for too few observations in a year
snotel_780_cull_count_days <- snotel_780_clean %>% 
  group_by(waterYear) %>% 
  count(waterYear) %>% 
  filter(n < 350)

snotel_780_cull_count_days
## # A tibble: 8 x 2
## # Groups:   waterYear [8]
##   waterYear     n
##       <dbl> <int>
## 1      1987   315
## 2      1994   336
## 3      1998   309
## 4      2009   342
## 5      2011   337
## 6      2013   336
## 7      2016   331
## 8      2017   324

1987, 1994, 1998, 2009, 2011, 2013, 2016, 2017 need to be culled.

snotel_780_clean_culled <- snotel_780_clean %>% 
  filter(waterYear != "1987" & waterYear != "1994" & waterYear != "1998" & waterYear != "2009" & waterYear != "2011" & waterYear != "2013" & waterYear != "2016" & waterYear != "2017")# & waterYear != "1993" & waterYear != "1994" & waterYear != "2021" & waterYear != "2022") & waterYear != "2014") #%>% 
  #filter(temperature_mean > -49)

ggplot(snotel_780_clean_culled, aes(x = Date, y = temp_diff)) + 
  geom_point() + #lwd = 2) +
  theme_few() +
  #geom_smooth(method = "lm", se=FALSE) +
  ylab('Daily temperature varience (°C)') + 
  xlab('Date')

ggplot(snotel_780_clean_culled, aes(x = Date, y = temperature_mean)) + 
  geom_point() + #lwd = 2) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('Daily temperature (°C)') + 
  xlab('Date')

temp_780_xts <- xts(snotel_780_clean_culled$temperature_mean, order.by = snotel_780_clean_culled$Date)

dygraph(temp_780_xts) %>%
  dyAxis("y", label = "Daily mean temperature (°C)") 
#snotel_780_clean_culled <- snotel_780_clean_culled %>% 
#  filter(temperature_mean < 19.3)

temp_780_xts <- xts(snotel_780_clean_culled$temperature_mean, order.by = snotel_780_clean_culled$Date)

dygraph(temp_780_xts) %>%
  dyAxis("y", label = "Daily mean temperature (°C)") 

Spud Mountain 780

Morrisey 6/28/2004

snotel_780_adjusted <- snotel_780_clean_culled %>%
  mutate(temp_ad = if_else(Date < "2004-06-28", ((5.3*10^(-7))*(temperature_mean^(4))+(3.72*10^(-5))*(temperature_mean^(3))-(2.16*10^(-3))*(temperature_mean^(2))-(7.32*10^(-2))*(temperature_mean)+1.37)+temperature_mean, temperature_mean))

Non-corrected

780 Detrended

#using the clean culled df:

#average water year temperature

yearly_wy_aver_780 <- snotel_780_adjusted %>% 
  group_by(waterYear) %>% 
  mutate(aver_ann_temp = mean(temperature_mean))

#Average temperature by day for all water years:

daily_wy_aver_780 <- yearly_wy_aver_780 %>% 
  group_by(daymonth) %>% 
  mutate(aver_day_temp = mean(aver_ann_temp))

#average mean temperature by day for the period of record:

daily_wy_aver_780 <- daily_wy_aver_780 %>% 
  group_by(daymonth) %>% 
  mutate(all_ave_temp = mean(daily_wy_aver_780$aver_day_temp))

# try to show all years as means. 
daily_wy_aver2_780 <-daily_wy_aver_780 %>% 
  group_by(waterDay) %>%
  mutate(date_temp = mean(temperature_mean))
  

daily_wy_aver2_780$date_temp <- signif(daily_wy_aver2_780$date_temp,3) #reduce the sig figs


ggplot(daily_wy_aver2_780, aes(x = waterDay, y = date_temp))+
  geom_line(size= 0.7) +
  theme_few() +
  ylab('Average Daily temperature (°C)') + 
  xlab('Day of water year')

780 SD

standard_dev_780 <- daily_wy_aver_780 %>% 
  group_by(waterYear) %>% 
  mutate(residual = (all_ave_temp-aver_ann_temp)+temperature_mean-aver_day_temp) %>% 
  mutate(deviation = abs(residual-lag(residual)))

standard_dev_all_780 <- standard_dev_780 %>% 
  group_by(waterYear) %>% 
  mutate(nmbr = n())

standard_dev_all_780 <- standard_dev_all_780 %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)

standard_dev_all_780 %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1988 8.083874
1989 8.173292
1990 7.631378
1991 7.796215
1992 7.011676
1993 7.893616
1995 7.478626
1996 7.773665
1997 7.856295
1999 6.828980
2000 7.722333
2001 8.147987
2002 8.545717
2003 7.955225
2004 7.944675
2005 7.146399
2006 7.088438
2007 7.424508
2008 7.859459
2010 7.733705
2012 7.461301
2014 7.143839
2015 6.533563
2018 6.864656
2019 7.580081
2020 7.727076
2021 7.724978
2022 7.146411
ggplot(standard_dev_all_780, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Non-corrected standard deviation of SNOTEL 780 average temperatures for water years 2005-2021

MK & SS for 780 (non-corrected)

sd_mk_780 <- mk.test(standard_dev_all_780$sd_2)
print(sd_mk_780)
## 
##  Mann-Kendall trend test
## 
## data:  standard_dev_all_780$sd_2
## z = -1.9954, n = 28, p-value = 0.046
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##            S         varS          tau 
## -102.0000000 2562.0000000   -0.2698413
sd_sens_780 <- sens.slope(standard_dev_all_780$sd_2)
print(sd_sens_780)
## 
##  Sen's slope
## 
## data:  standard_dev_all_780$sd_2
## z = -1.9954, n = 28, p-value = 0.046
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.0394954014 -0.0004267439
## sample estimates:
## Sen's slope 
## -0.01908281

Corrected

780 Detrended (corrected)

#using the clean culled df:
#average water year temperature
yearly_wy_aver_780_ad <- snotel_780_adjusted %>% 
  group_by(waterYear) %>% 
  mutate(aver_ann_temp_ad = mean(temp_ad))
#Average temperature by day for all water years:
daily_wy_aver_780_ad <- yearly_wy_aver_780_ad %>% 
  group_by(daymonth) %>% 
  mutate(aver_day_temp_ad = mean(aver_ann_temp_ad))
#average mean temperature by day for the period of record:
daily_wy_aver_780_ad <- daily_wy_aver_780_ad %>% 
  group_by(daymonth) %>% 
  mutate(all_ave_temp_ad = mean(daily_wy_aver_780_ad$aver_day_temp_ad))
# try to show all years as means. 
daily_wy_aver2_780_ad <-daily_wy_aver_780_ad %>% 
  group_by(waterDay) %>%
  mutate(date_temp_ad = mean(temp_ad))
  
daily_wy_aver2_780_ad$date_temp_ad <- signif(daily_wy_aver2_780_ad$date_temp_ad,3) #reduce the sig figs
ggplot(daily_wy_aver2_780_ad, aes(x = waterDay, y = date_temp_ad))+
  geom_line(size= 0.7) +
  theme_few() +
  ylab('Average Daily temperature (°C)') + 
  xlab('Day of water year')

780 SS (corrected)

standard_dev_780_ad <- daily_wy_aver_780_ad %>% 
  group_by(waterYear) %>% 
  #filter(waterYear >= 1987 & waterYear <= 2021) %>% 
  mutate(residual = (all_ave_temp_ad-aver_ann_temp_ad)+temp_ad-aver_day_temp_ad) %>% 
  mutate(deviation = abs(residual-lag(residual)))
standard_dev_all_780_ad <- standard_dev_780_ad %>% 
  group_by(waterYear) %>% 
  mutate(nmbr = n())
standard_dev_all_780_ad <- standard_dev_all_780_ad %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)
standard_dev_all_780_ad %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1988 7.530892
1989 7.629513
1990 7.085085
1991 7.275264
1992 6.494536
1993 7.336765
1995 6.928211
1996 7.209777
1997 7.307706
1999 6.331029
2000 7.141268
2001 7.555861
2002 7.925084
2003 7.356618
2004 7.299749
2005 7.146735
2006 7.089360
2007 7.425654
2008 7.860535
2010 7.734756
2012 7.462985
2014 7.144698
2015 6.534943
2018 6.866003
2019 7.581136
2020 7.728271
2021 7.725902
2022 7.147773
ggplot(standard_dev_all_780_ad, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Morrisey-corrected standard deviation of SNOTEL 780 average temperatures for water years 1986-2021

MK & SS 780 (corrected)

sd_mk_780_ad <- mk.test(standard_dev_all_780_ad$sd_2)
print(sd_mk_780_ad)
## 
##  Mann-Kendall trend test
## 
## data:  standard_dev_all_780_ad$sd_2
## z = 0.84953, n = 28, p-value = 0.3956
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##            S         varS          tau 
##   44.0000000 2562.0000000    0.1164021
sd_sens_780_ad <- sens.slope(standard_dev_all_780_ad$sd_2)
print(sd_sens_780_ad)
## 
##  Sen's slope
## 
## data:  standard_dev_all_780_ad$sd_2
## z = 0.84953, n = 28, p-value = 0.3956
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.01274116  0.02720599
## sample estimates:
## Sen's slope 
## 0.007453894

Summer and Winter SD NOT-CORRECTED

Summer

summer_standard_dev_all_780 <- standard_dev_780 %>%
  filter(waterDay >= 244 & waterDay <= 335) %>%
  group_by(waterYear) %>% 
  mutate(nmbr = n())

summer_standard_dev_all_780 <- summer_standard_dev_all_780 %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)

summer_standard_dev_all_780 %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1988 2.432792
1989 2.950137
1990 2.664522
1991 2.411156
1992 2.824120
1993 3.318665
1995 3.390624
1996 2.250871
1997 2.379508
1999 2.724005
2000 1.835908
2001 2.489843
2002 2.344072
2003 2.822363
2004 2.588494
2005 3.022099
2006 2.053504
2007 2.434362
2008 2.304875
2010 2.306507
2012 1.543810
2014 1.989689
2015 2.332147
2018 1.813695
2019 2.431221
2020 2.452038
2021 2.236513
2022 2.015161
ggplot(summer_standard_dev_all_780, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Non-corrected standard deviation of SNOTEL 780 average summer temperatures for water years 2005-2021

summer MK & SS for 780 (non-corrected)

summer_sd_mk_780 <- mk.test(summer_standard_dev_all_780$sd_2)
print(summer_sd_mk_780)
## 
##  Mann-Kendall trend test
## 
## data:  summer_standard_dev_all_780$sd_2
## z = -2.7462, n = 28, p-value = 0.00603
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##            S         varS          tau 
## -140.0000000 2562.0000000   -0.3703704
summer_sd_sens_780 <- sens.slope(summer_standard_dev_all_780$sd_2)
print(summer_sd_sens_780)
## 
##  Sen's slope
## 
## data:  summer_standard_dev_all_780$sd_2
## z = -2.7462, n = 28, p-value = 0.00603
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.044102535 -0.006660488
## sample estimates:
## Sen's slope 
## -0.02494145

Winter

winter_standard_dev_all_780 <- standard_dev_780 %>%
  filter(waterDay >= 32 & waterDay <= 182) %>%
  group_by(waterYear) %>% 
  mutate(nmbr = n())

winter_standard_dev_all_780 <- winter_standard_dev_all_780 %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)

winter_standard_dev_all_780 %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1988 4.728111
1989 5.529818
1990 4.915755
1991 4.625673
1992 3.366642
1993 3.857739
1995 4.159659
1996 4.941637
1997 4.864556
1999 4.008686
2000 4.800600
2001 3.896151
2002 5.030428
2003 4.105646
2004 5.103992
2005 3.891688
2006 4.388333
2007 5.052493
2008 5.353871
2010 4.321493
2012 4.136622
2014 4.085958
2015 4.487931
2018 4.168824
2019 3.905352
2020 4.270359
2021 4.213932
2022 4.574223
ggplot(winter_standard_dev_all_780, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Non-corrected standard deviation of SNOTEL 780 average winter temperatures for water years 2005-2021

winter MK & SS for 780 (non-corrected)

winter_sd_mk_780 <- mk.test(winter_standard_dev_all_780$sd_2)
print(winter_sd_mk_780)
## 
##  Mann-Kendall trend test
## 
## data:  winter_standard_dev_all_780$sd_2
## z = -0.53343, n = 28, p-value = 0.5937
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##             S          varS           tau 
##  -28.00000000 2562.00000000   -0.07407407
winter_sd_sens_780 <- sens.slope(winter_standard_dev_all_780$sd_2)
print(winter_sd_sens_780)
## 
##  Sen's slope
## 
## data:  winter_standard_dev_all_780$sd_2
## z = -0.53343, n = 28, p-value = 0.5937
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.03816715  0.01859223
## sample estimates:
## Sen's slope 
## -0.01321226

Summer and Winter SD CORRECTED

Summer

summer_standard_dev_all_780_ad <- standard_dev_780_ad %>% 
  filter(waterDay >= 244 & waterDay <= 335) %>%
  group_by(waterYear) %>% 
  mutate(nmbr = n())
summer_standard_dev_all_780_ad <- summer_standard_dev_all_780_ad %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)
summer_standard_dev_all_780_ad %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1988 2.192241
1989 2.645295
1990 2.393290
1991 2.174228
1992 2.544730
1993 2.991736
1995 3.050477
1996 2.016136
1997 2.142284
1999 2.459696
2000 1.644421
2001 2.239012
2002 2.097917
2003 2.527899
2004 2.423734
2005 3.021150
2006 2.051951
2007 2.434476
2008 2.305532
2010 2.304951
2012 1.543208
2014 1.987540
2015 2.333379
2018 1.813470
2019 2.429766
2020 2.452190
2021 2.237222
2022 2.014534
ggplot(summer_standard_dev_all_780_ad, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Morrisey-corrected standard deviation of SNOTEL 780 average summer temperatures for water years 1986-2021

summer MK & SS 780 (corrected)

summer_sd_mk_780_ad <- mk.test(summer_standard_dev_all_780_ad$sd_2)
print(summer_sd_mk_780_ad)
## 
##  Mann-Kendall trend test
## 
## data:  summer_standard_dev_all_780_ad$sd_2
## z = -1.4422, n = 28, p-value = 0.1492
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##            S         varS          tau 
##  -74.0000000 2562.0000000   -0.1957672
summer_sd_sens_780_ad <- sens.slope(summer_standard_dev_all_780_ad$sd_2)
print(summer_sd_sens_780_ad)
## 
##  Sen's slope
## 
## data:  summer_standard_dev_all_780_ad$sd_2
## z = -1.4422, n = 28, p-value = 0.1492
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.026977267  0.004499003
## sample estimates:
##  Sen's slope 
## -0.009732141

Winter

winter_standard_dev_all_780_ad <- standard_dev_780_ad %>% 
  filter(waterDay >= 32 & waterDay <= 182) %>%
  group_by(waterYear) %>% 
  mutate(nmbr = n())
winter_standard_dev_all_780_ad <- winter_standard_dev_all_780_ad %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)
winter_standard_dev_all_780_ad %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1988 4.558562
1989 5.338146
1990 4.702000
1991 4.482169
1992 3.217724
1993 3.722134
1995 3.982988
1996 4.735689
1997 4.662361
1999 3.836986
2000 4.561800
2001 3.751725
2002 4.818090
2003 3.939896
2004 4.897779
2005 3.891135
2006 4.388210
2007 5.053531
2008 5.353295
2010 4.321866
2012 4.138875
2014 4.086817
2015 4.488516
2018 4.170037
2019 3.905450
2020 4.270195
2021 4.213896
2022 4.574664
ggplot(winter_standard_dev_all_780_ad, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Morrisey-corrected standard deviation of SNOTEL 780 average winter temperatures for water years 1986-2021

winter MK & SS 780 (corrected)

winter_sd_mk_780_ad <- mk.test(winter_standard_dev_all_780_ad$sd_2)
print(winter_sd_mk_780_ad)
## 
##  Mann-Kendall trend test
## 
## data:  winter_standard_dev_all_780_ad$sd_2
## z = -0.05927, n = 28, p-value = 0.9527
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##             S          varS           tau 
##   -4.00000000 2562.00000000   -0.01058201
winter_sd_sens_780_ad <- sens.slope(winter_standard_dev_all_780_ad$sd_2)
print(winter_sd_sens_780_ad)
## 
##  Sen's slope
## 
## data:  winter_standard_dev_all_780_ad$sd_2
## z = -0.05927, n = 28, p-value = 0.9527
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.0289316  0.0270756
## sample estimates:
##  Sen's slope 
## -0.003745777

Spring and Fall SD NOT-CORRECTED

Spring

spring_standard_dev_all_780 <- standard_dev_780 %>%
  filter(waterDay >= 183 & waterDay <= 243) %>%
  group_by(waterYear) %>% 
  mutate(nmbr = n())

spring_standard_dev_all_780 <- spring_standard_dev_all_780 %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)

spring_standard_dev_all_780 %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1988 4.567627
1989 4.228260
1990 3.057619
1991 4.730430
1992 3.034834
1993 4.192641
1995 3.802733
1996 5.113518
1997 5.267694
1999 4.917503
2000 4.798997
2001 5.023133
2002 3.766961
2003 5.115135
2004 3.894822
2005 4.391167
2006 3.800219
2007 3.835628
2008 4.275746
2010 4.589115
2012 3.889202
2014 4.646716
2015 3.038959
2018 4.068844
2019 3.247755
2020 4.028921
2021 3.473810
2022 4.276977
ggplot(spring_standard_dev_all_780, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Non-corrected standard deviation of SNOTEL 780 average spring temperatures for water years 2005-2021

spring MK & SS for 780 (non-corrected)

spring_sd_mk_780 <- mk.test(spring_standard_dev_all_780$sd_2)
print(spring_sd_mk_780)
## 
##  Mann-Kendall trend test
## 
## data:  spring_standard_dev_all_780$sd_2
## z = -1.0471, n = 28, p-value = 0.2951
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##            S         varS          tau 
##  -54.0000000 2562.0000000   -0.1428571
spring_sd_sens_780 <- sens.slope(spring_standard_dev_all_780$sd_2)
print(spring_sd_sens_780)
## 
##  Sen's slope
## 
## data:  spring_standard_dev_all_780$sd_2
## z = -1.0471, n = 28, p-value = 0.2951
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.05499466  0.01785793
## sample estimates:
## Sen's slope 
## -0.02258097

Fall

Fall is split each water year in the middle of the season. This analysis splits the fall season between the preceding water year and the subsequent water year.

fall_standard_dev_all_780 <- standard_dev_780 %>%
  filter(waterDay >= 336 | waterDay <= 31) %>% 
  group_by(waterYear) %>% 
  mutate(nmbr = n())

fall_standard_dev_all_780 <- fall_standard_dev_all_780 %>% 
  #group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)

fall_standard_dev_all_780 %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1988 3.405576
1989 2.837940
1990 5.043475
1991 3.802209
1992 4.980256
1993 3.524913
1995 4.724390
1996 4.059580
1997 5.758385
1999 4.016174
2000 3.680387
2001 4.845558
2002 3.402886
2003 4.885723
2004 3.641135
2005 4.251468
2006 3.091174
2007 4.357294
2008 3.488272
2010 5.654828
2012 4.382478
2014 5.094555
2015 2.960924
2018 3.367012
2019 4.658573
2020 5.768263
2021 3.983521
2022 4.913202
ggplot(fall_standard_dev_all_780, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Non-corrected standard deviation of SNOTEL 780 average fall temperatures for water years 2005-2021. Note that the season is split by the water year.

fall MK & SS for 780 (non-corrected)

fall_sd_mk_780 <- mk.test(fall_standard_dev_all_780$sd_2)
print(fall_sd_mk_780)
## 
##  Mann-Kendall trend test
## 
## data:  fall_standard_dev_all_780$sd_2
## z = 0.69148, n = 28, p-value = 0.4893
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##           S        varS         tau 
## 3.60000e+01 2.56200e+03 9.52381e-02
fall_sd_sens_780 <- sens.slope(fall_standard_dev_all_780$sd_2)
print(fall_sd_sens_780)
## 
##  Sen's slope
## 
## data:  fall_standard_dev_all_780$sd_2
## z = 0.69148, n = 28, p-value = 0.4893
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.02435884  0.06178423
## sample estimates:
## Sen's slope 
##  0.02203356

Spring and Fall SD CORRECTED

Spring

spring_standard_dev_all_780_ad <- standard_dev_780_ad %>% 
  filter(waterDay >= 183 & waterDay <= 243) %>%
  group_by(waterYear) %>% 
  mutate(nmbr = n())
spring_standard_dev_all_780_ad <- spring_standard_dev_all_780_ad %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)
spring_standard_dev_all_780_ad %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1988 4.224138
1989 3.883632
1990 2.808739
1991 4.420339
1992 2.785943
1993 3.874317
1995 3.540844
1996 4.706001
1997 4.906711
1999 4.589927
2000 4.388571
2001 4.633861
2002 3.434156
2003 4.711946
2004 3.579614
2005 4.390524
2006 3.800749
2007 3.835523
2008 4.275406
2010 4.589263
2012 3.889830
2014 4.646263
2015 3.038727
2018 4.069722
2019 3.247990
2020 4.028829
2021 3.473698
2022 4.277082
ggplot(spring_standard_dev_all_780_ad, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Morrisey-corrected standard deviation of SNOTEL 780 average spring temperatures for water years 1986-2021

spring MK & SS 780 (corrected)

spring_sd_mk_780_ad <- mk.test(spring_standard_dev_all_780_ad$sd_2)
print(spring_sd_mk_780_ad)
## 
##  Mann-Kendall trend test
## 
## data:  spring_standard_dev_all_780_ad$sd_2
## z = -0.21732, n = 28, p-value = 0.828
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##             S          varS           tau 
##  -12.00000000 2562.00000000   -0.03174603
spring_sd_sens_780_ad <- sens.slope(spring_standard_dev_all_780_ad$sd_2)
print(spring_sd_sens_780_ad)
## 
##  Sen's slope
## 
## data:  spring_standard_dev_all_780_ad$sd_2
## z = -0.21732, n = 28, p-value = 0.828
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.03522533  0.02916070
## sample estimates:
##  Sen's slope 
## -0.003812139

Fall

fall_standard_dev_all_780_ad <- standard_dev_780_ad %>% 
  filter(waterDay >= 336 | waterDay <= 31) %>%
  group_by(waterYear) %>% 
  mutate(nmbr = n())
fall_standard_dev_all_780_ad <- fall_standard_dev_all_780_ad %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)
fall_standard_dev_all_780_ad %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1988 3.098516
1989 2.577628
1990 4.611774
1991 3.502476
1992 4.615316
1993 3.221676
1995 4.314500
1996 3.717907
1997 5.315247
1999 3.684835
2000 3.346710
2001 4.431032
2002 3.104624
2003 4.481383
2004 3.399599
2005 4.252485
2006 3.094317
2007 4.358693
2008 3.490485
2010 5.656616
2012 4.384573
2014 5.094916
2015 2.962188
2018 3.368243
2019 4.660850
2020 5.770472
2021 3.982469
2022 4.914485
ggplot(fall_standard_dev_all_780_ad, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Morrisey-corrected standard deviation of SNOTEL 780 average fall temperatures for water years 1986-2021. Note that the fall season is split by the water year.

fall MK & SS 780 (corrected)

fall_sd_mk_780_ad <- mk.test(fall_standard_dev_all_780_ad$sd_2)
print(fall_sd_mk_780_ad)
## 
##  Mann-Kendall trend test
## 
## data:  fall_standard_dev_all_780_ad$sd_2
## z = 1.5608, n = 28, p-value = 0.1186
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##            S         varS          tau 
##   80.0000000 2562.0000000    0.2116402
fall_sd_sens_780_ad <- sens.slope(fall_standard_dev_all_780_ad$sd_2)
print(fall_sd_sens_780_ad)
## 
##  Sen's slope
## 
## data:  fall_standard_dev_all_780_ad$sd_2
## z = 1.5608, n = 28, p-value = 0.1186
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.01185377  0.07663007
## sample estimates:
## Sen's slope 
##  0.03030447

Stump Lakes 797

Morrisey 7/22/2005

snotel_797 <- SNOTEL_san_juan_Area %>% 
  filter(site_id == "797")
#str(snotel_797) # check the date, usually a character.  

snotel_797$Date <- as.Date(snotel_797$date) #change date from character to date format, capitalize to work with Water year functon from NWIS.

#THIS WILL CHANGE FOR EACH STATION
snotel_797_clean <- snotel_797 %>% # filter for the timeframe
  filter(Date >= "1979-10-01" & Date <= "2022-09-30") %>%
  #filter(temperature_mean >= -30 & temperature_mean <= 20) %>% # removing outliers   
  addWaterYear() %>% 
  mutate(daymonth = format(as.Date(Date), "%d-%m")) %>% 
  na.omit()

#adding water day using difftime (SUPER COOL. example from [this](https://stackoverflow.com/questions/48123049/create-day-index-based-on-water-year))

snotel_797_clean <- snotel_797_clean %>% 
  group_by(waterYear)%>% 
  mutate(waterDay = (as.integer(difftime(Date, ymd(paste0(waterYear - 1 ,'-09-30')), units = "days"))))
# Check for outliers

ggplot(snotel_797_clean, aes(x = Date, y = temperature_mean)) +
  geom_point() + #lwd = 2) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('Daily temperature (°C)') + 
  xlab('Date')

snotel_797_clean <- snotel_797_clean %>% 
  mutate(temp_diff = abs(temperature_min - temperature_max)) %>% 
  filter(temperature_mean > -40) %>% 
  filter(temperature_mean < 40)
ggplot(snotel_797_clean, aes(x = Date, y = temp_diff)) + 
  geom_point() + #lwd = 2) +
  theme_few() +
  #geom_smooth(method = "lm", se=FALSE) +
  ylab('Daily temperature varience (°C)') + 
  xlab('Date')

Per Steven’s advice: :If there are more than 15 missing days, then…remove that year”

# filtering for temperature anomalies
#snotel_797_cull_count <- snotel_797_clean %>% 
#  filter(temperature_min > -40) %>% 
#  count(waterYear)

#snotel_797_cull_count

# filtering for too few observations in a year
snotel_797_cull_count_days <- snotel_797_clean %>% 
  group_by(waterYear) %>% 
  count(waterYear) %>% 
  filter(n < 350)

snotel_797_cull_count_days
## # A tibble: 5 x 2
## # Groups:   waterYear [5]
##   waterYear     n
##       <dbl> <int>
## 1      1987   267
## 2      1993   320
## 3      1994   274
## 4      2005   329
## 5      2006   327

1987, 1993, 1994, 2005, 2006 need to be culled.

snotel_797_clean_culled <- snotel_797_clean %>% 
  filter(waterYear != "1994" & waterYear != "2005" & waterYear != "2006" & waterYear != "1993" & waterYear != "1987")# & waterYear != "2021" & waterYear != "2022") & waterYear != "2014") #%>% 
  #filter(temperature_mean > -49)

ggplot(snotel_797_clean_culled, aes(x = Date, y = temp_diff)) + 
  geom_point() + #lwd = 2) +
  theme_few() +
  #geom_smooth(method = "lm", se=FALSE) +
  ylab('Daily temperature varience (°C)') + 
  xlab('Date')

ggplot(snotel_797_clean_culled, aes(x = Date, y = temperature_mean)) + 
  geom_point() + #lwd = 2) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('Daily temperature (°C)') + 
  xlab('Date')

temp_797_xts <- xts(snotel_797_clean_culled$temperature_mean, order.by = snotel_797_clean_culled$Date)

dygraph(temp_797_xts) %>%
  dyAxis("y", label = "Daily mean temperature (°C)") 
#snotel_797_clean_culled <- snotel_797_clean_culled %>% 
#  filter(temperature_mean < 19.3)

temp_797_xts <- xts(snotel_797_clean_culled$temperature_mean, order.by = snotel_797_clean_culled$Date)

dygraph(temp_797_xts) %>%
  dyAxis("y", label = "Daily mean temperature (°C)") 

Stump Lakes 797

Morrisey 7/22/2005

snotel_797_adjusted <- snotel_797_clean_culled %>%
  mutate(temp_ad = if_else(Date < "2005-07-22", ((5.3*10^(-7))*(temperature_mean^(4))+(3.72*10^(-5))*(temperature_mean^(3))-(2.16*10^(-3))*(temperature_mean^(2))-(7.32*10^(-2))*(temperature_mean)+1.37)+temperature_mean, temperature_mean))

Non-corrected

797 Detrended

#using the clean culled df:

#average water year temperature

yearly_wy_aver_797 <- snotel_797_adjusted %>% 
  group_by(waterYear) %>% 
  mutate(aver_ann_temp = mean(temperature_mean))

#Average temperature by day for all water years:

daily_wy_aver_797 <- yearly_wy_aver_797 %>% 
  group_by(daymonth) %>% 
  mutate(aver_day_temp = mean(aver_ann_temp))

#average mean temperature by day for the period of record:

daily_wy_aver_797 <- daily_wy_aver_797 %>% 
  group_by(daymonth) %>% 
  mutate(all_ave_temp = mean(daily_wy_aver_797$aver_day_temp))

# try to show all years as means. 
daily_wy_aver2_797 <-daily_wy_aver_797 %>% 
  group_by(waterDay) %>%
  mutate(date_temp = mean(temperature_mean))
  

daily_wy_aver2_797$date_temp <- signif(daily_wy_aver2_797$date_temp,3) #reduce the sig figs


ggplot(daily_wy_aver2_797, aes(x = waterDay, y = date_temp))+
  geom_line(size= 0.7) +
  theme_few() +
  ylab('Average Daily temperature (°C)') + 
  xlab('Day of water year')

797 SD

standard_dev_797 <- daily_wy_aver_797 %>% 
  group_by(waterYear) %>% 
  mutate(residual = (all_ave_temp-aver_ann_temp)+temperature_mean-aver_day_temp) %>% 
  mutate(deviation = abs(residual-lag(residual)))

standard_dev_all_797 <- standard_dev_797 %>% 
  group_by(waterYear) %>% 
  mutate(nmbr = n())

standard_dev_all_797 <- standard_dev_all_797 %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)

standard_dev_all_797 %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1988 8.133643
1989 10.300128
1990 7.808751
1991 9.471092
1992 7.312520
1995 7.694636
1996 7.953496
1997 8.069085
1998 8.367447
1999 7.015052
2000 7.935172
2001 8.545423
2002 9.270169
2003 8.084230
2004 9.099232
2007 7.603452
2008 8.008843
2009 7.184718
2010 7.913867
2011 7.886632
2012 7.696409
2013 8.096842
2014 7.327713
2015 6.737528
2016 7.565177
2017 7.316786
2018 7.076498
2019 7.800277
2020 7.872608
2021 7.863889
2022 7.341735
ggplot(standard_dev_all_797, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Non-corrected standard deviation of SNOTEL 797 average temperatures for water years 2005-2021

MK & SS for 797 (non-corrected)

sd_mk_797 <- mk.test(standard_dev_all_797$sd_2)
print(sd_mk_797)
## 
##  Mann-Kendall trend test
## 
## data:  standard_dev_all_797$sd_2
## z = -2.5495, n = 31, p-value = 0.01079
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##            S         varS          tau 
## -151.0000000 3461.6666667   -0.3247312
sd_sens_797 <- sens.slope(standard_dev_all_797$sd_2)
print(sd_sens_797)
## 
##  Sen's slope
## 
## data:  standard_dev_all_797$sd_2
## z = -2.5495, n = 31, p-value = 0.01079
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.055919889 -0.005393295
## sample estimates:
## Sen's slope 
## -0.02911914

Corrected

797 Detrended (corrected)

#using the clean culled df:
#average water year temperature
yearly_wy_aver_797_ad <- snotel_797_adjusted %>% 
  group_by(waterYear) %>% 
  mutate(aver_ann_temp_ad = mean(temp_ad))
#Average temperature by day for all water years:
daily_wy_aver_797_ad <- yearly_wy_aver_797_ad %>% 
  group_by(daymonth) %>% 
  mutate(aver_day_temp_ad = mean(aver_ann_temp_ad))
#average mean temperature by day for the period of record:
daily_wy_aver_797_ad <- daily_wy_aver_797_ad %>% 
  group_by(daymonth) %>% 
  mutate(all_ave_temp_ad = mean(daily_wy_aver_797_ad$aver_day_temp_ad))
# try to show all years as means. 
daily_wy_aver2_797_ad <-daily_wy_aver_797_ad %>% 
  group_by(waterDay) %>%
  mutate(date_temp_ad = mean(temp_ad))
  
daily_wy_aver2_797_ad$date_temp_ad <- signif(daily_wy_aver2_797_ad$date_temp_ad,3) #reduce the sig figs
ggplot(daily_wy_aver2_797_ad, aes(x = waterDay, y = date_temp_ad))+
  geom_line(size= 0.7) +
  theme_few() +
  ylab('Average Daily temperature (°C)') + 
  xlab('Day of water year')

797 SS (corrected)

standard_dev_797_ad <- daily_wy_aver_797_ad %>% 
  group_by(waterYear) %>% 
  #filter(waterYear >= 1987 & waterYear <= 2021) %>% 
  mutate(residual = (all_ave_temp_ad-aver_ann_temp_ad)+temp_ad-aver_day_temp_ad) %>% 
  mutate(deviation = abs(residual-lag(residual)))
standard_dev_all_797_ad <- standard_dev_797_ad %>% 
  group_by(waterYear) %>% 
  mutate(nmbr = n())
standard_dev_all_797_ad <- standard_dev_all_797_ad %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)
standard_dev_all_797_ad %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1988 7.629765
1989 9.567031
1990 7.287673
1991 8.816683
1992 6.729102
1995 7.165683
1996 7.422437
1997 7.545973
1998 7.813938
1999 6.542177
2000 7.377392
2001 7.978790
2002 8.614161
2003 7.487087
2004 8.402698
2007 7.603448
2008 8.008551
2009 7.184680
2010 7.914300
2011 7.886697
2012 7.696830
2013 8.096444
2014 7.327715
2015 6.737458
2016 7.565155
2017 7.316299
2018 7.076457
2019 7.800532
2020 7.873011
2021 7.863666
2022 7.341402
ggplot(standard_dev_all_797_ad, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Morrisey-corrected standard deviation of SNOTEL 797 average temperatures for water years 1986-2021

MK & SS 797 (corrected)

sd_mk_797_ad <- mk.test(standard_dev_all_797_ad$sd_2)
print(sd_mk_797_ad)
## 
##  Mann-Kendall trend test
## 
## data:  standard_dev_all_797_ad$sd_2
## z = -0.30594, n = 31, p-value = 0.7597
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##             S          varS           tau 
##  -19.00000000 3461.66666667   -0.04086022
sd_sens_797_ad <- sens.slope(standard_dev_all_797_ad$sd_2)
print(sd_sens_797_ad)
## 
##  Sen's slope
## 
## data:  standard_dev_all_797_ad$sd_2
## z = -0.30594, n = 31, p-value = 0.7597
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.03291859  0.02011237
## sample estimates:
## Sen's slope 
## -0.00412891

Summer and Winter SD NOT-CORRECTED

Summer

summer_standard_dev_all_797 <- standard_dev_797 %>%
  filter(waterDay >= 244 & waterDay <= 335) %>%
  group_by(waterYear) %>% 
  mutate(nmbr = n())

summer_standard_dev_all_797 <- summer_standard_dev_all_797 %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)

summer_standard_dev_all_797 %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1988 2.483579
1989 6.242646
1990 3.152975
1991 5.429548
1992 2.710330
1995 3.599372
1996 2.265251
1997 2.523495
1998 3.270027
1999 2.702494
2000 1.841536
2001 2.374428
2002 4.011811
2003 3.002708
2004 4.617372
2007 2.509460
2008 2.392826
2009 3.033721
2010 2.406375
2011 1.963297
2012 1.651274
2013 1.822955
2014 1.971373
2015 2.430667
2016 2.573683
2017 2.033856
2018 1.929844
2019 2.568367
2020 2.416969
2021 2.211379
2022 2.240925
ggplot(summer_standard_dev_all_797, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Non-corrected standard deviation of SNOTEL 797 average summer temperatures for water years 2005-2021

summer MK & SS for 797 (non-corrected)

summer_sd_mk_797 <- mk.test(summer_standard_dev_all_797$sd_2)
print(summer_sd_mk_797)
## 
##  Mann-Kendall trend test
## 
## data:  summer_standard_dev_all_797$sd_2
## z = -2.8894, n = 31, p-value = 0.00386
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##            S         varS          tau 
## -171.0000000 3461.6666667   -0.3677419
summer_sd_sens_797 <- sens.slope(summer_standard_dev_all_797$sd_2)
print(summer_sd_sens_797)
## 
##  Sen's slope
## 
## data:  summer_standard_dev_all_797$sd_2
## z = -2.8894, n = 31, p-value = 0.00386
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.07024220 -0.01064723
## sample estimates:
## Sen's slope 
##  -0.0390493

Winter

winter_standard_dev_all_797 <- standard_dev_797 %>%
  filter(waterDay >= 32 & waterDay <= 182) %>%
  group_by(waterYear) %>% 
  mutate(nmbr = n())

winter_standard_dev_all_797 <- winter_standard_dev_all_797 %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)

winter_standard_dev_all_797 %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1988 4.803631
1989 5.606557
1990 4.869386
1991 4.723788
1992 8.274717
1995 4.191396
1996 5.047344
1997 4.911177
1998 4.414866
1999 4.076039
2000 4.792439
2001 4.056284
2002 5.051351
2003 6.605544
2004 5.935687
2007 5.158984
2008 5.437225
2009 4.556869
2010 4.265090
2011 5.095026
2012 4.180748
2013 5.560780
2014 4.130668
2015 4.465995
2016 4.828614
2017 5.036457
2018 4.296132
2019 3.977055
2020 4.262699
2021 4.277143
2022 4.644949
ggplot(winter_standard_dev_all_797, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Non-corrected standard deviation of SNOTEL 797 average winter temperatures for water years 2005-2021

winter MK & SS for 797 (non-corrected)

winter_sd_mk_797 <- mk.test(winter_standard_dev_all_797$sd_2)
print(winter_sd_mk_797)
## 
##  Mann-Kendall trend test
## 
## data:  winter_standard_dev_all_797$sd_2
## z = -1.6317, n = 31, p-value = 0.1028
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##            S         varS          tau 
##  -97.0000000 3461.6666667   -0.2086022
winter_sd_sens_797 <- sens.slope(winter_standard_dev_all_797$sd_2)
print(winter_sd_sens_797)
## 
##  Sen's slope
## 
## data:  winter_standard_dev_all_797$sd_2
## z = -1.6317, n = 31, p-value = 0.1028
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.047479072  0.004202205
## sample estimates:
## Sen's slope 
## -0.02251882

Summer and Winter SD CORRECTED

Summer

summer_standard_dev_all_797_ad <- standard_dev_797_ad %>% 
  filter(waterDay >= 244 & waterDay <= 335) %>%
  group_by(waterYear) %>% 
  mutate(nmbr = n())
summer_standard_dev_all_797_ad <- summer_standard_dev_all_797_ad %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)
summer_standard_dev_all_797_ad %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1988 2.245034
1989 5.623882
1990 2.834998
1991 4.898820
1992 2.446780
1995 3.243187
1996 2.033137
1997 2.276214
1998 2.950593
1999 2.446501
2000 1.651046
2001 2.140749
2002 3.621940
2003 2.691961
2004 4.139630
2007 2.509660
2008 2.392731
2009 3.033066
2010 2.406356
2011 1.963820
2012 1.650528
2013 1.822647
2014 1.971575
2015 2.431067
2016 2.572877
2017 2.033915
2018 1.929470
2019 2.568532
2020 2.416814
2021 2.211819
2022 2.241472
ggplot(summer_standard_dev_all_797_ad, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Morrisey-corrected standard deviation of SNOTEL 797 average summer temperatures for water years 1986-2021

summer MK & SS 797 (corrected)

summer_sd_mk_797_ad <- mk.test(summer_standard_dev_all_797_ad$sd_2)
print(summer_sd_mk_797_ad)
## 
##  Mann-Kendall trend test
## 
## data:  summer_standard_dev_all_797_ad$sd_2
## z = -2.1076, n = 31, p-value = 0.03507
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##            S         varS          tau 
## -125.0000000 3461.6666667   -0.2688172
summer_sd_sens_797_ad <- sens.slope(summer_standard_dev_all_797_ad$sd_2)
print(summer_sd_sens_797_ad)
## 
##  Sen's slope
## 
## data:  summer_standard_dev_all_797_ad$sd_2
## z = -2.1076, n = 31, p-value = 0.03507
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.056855522 -0.001102443
## sample estimates:
## Sen's slope 
## -0.02502598

Winter

winter_standard_dev_all_797_ad <- standard_dev_797_ad %>% 
  filter(waterDay >= 32 & waterDay <= 182) %>%
  group_by(waterYear) %>% 
  mutate(nmbr = n())
winter_standard_dev_all_797_ad <- winter_standard_dev_all_797_ad %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)
winter_standard_dev_all_797_ad %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1988 4.675154
1989 5.455092
1990 4.699934
1991 4.621363
1992 7.618416
1995 4.055758
1996 4.882491
1997 4.733803
1998 4.270832
1999 3.936098
2000 4.596529
2001 3.946228
2002 4.876426
2003 6.186776
2004 5.656983
2007 5.158963
2008 5.435754
2009 4.556054
2010 4.265451
2011 5.094722
2012 4.180574
2013 5.559375
2014 4.130789
2015 4.465776
2016 4.828268
2017 5.035310
2018 4.295282
2019 3.976437
2020 4.262273
2021 4.276695
2022 4.643422
ggplot(winter_standard_dev_all_797_ad, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Morrisey-corrected standard deviation of SNOTEL 797 average winter temperatures for water years 1986-2021

winter MK & SS 797 (corrected)

winter_sd_mk_797_ad <- mk.test(winter_standard_dev_all_797_ad$sd_2)
print(winter_sd_mk_797_ad)
## 
##  Mann-Kendall trend test
## 
## data:  winter_standard_dev_all_797_ad$sd_2
## z = -1.2237, n = 31, p-value = 0.221
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##            S         varS          tau 
##  -73.0000000 3461.6666667   -0.1569892
winter_sd_sens_797_ad <- sens.slope(winter_standard_dev_all_797_ad$sd_2)
print(winter_sd_sens_797_ad)
## 
##  Sen's slope
## 
## data:  winter_standard_dev_all_797_ad$sd_2
## z = -1.2237, n = 31, p-value = 0.221
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.040200980  0.009852644
## sample estimates:
## Sen's slope 
## -0.01504631

Spring and Fall SD NOT-CORRECTED

Spring

spring_standard_dev_all_797 <- standard_dev_797 %>%
  filter(waterDay >= 183 & waterDay <= 243) %>%
  group_by(waterYear) %>% 
  mutate(nmbr = n())

spring_standard_dev_all_797 <- spring_standard_dev_all_797 %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)

spring_standard_dev_all_797 %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1988 4.462315
1989 6.704749
1990 3.169499
1991 5.242763
1992 3.455906
1995 3.771067
1996 5.100778
1997 5.384272
1998 5.105199
1999 5.001348
2000 4.840524
2001 5.733192
2002 4.596848
2003 5.240126
2004 8.356708
2007 3.904360
2008 4.253932
2009 4.894273
2010 4.695508
2011 4.204462
2012 3.949375
2013 4.244266
2014 4.753201
2015 3.083733
2016 3.789221
2017 4.005562
2018 3.999210
2019 3.425048
2020 4.110832
2021 3.589611
2022 4.372199
ggplot(spring_standard_dev_all_797, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Non-corrected standard deviation of SNOTEL 797 average spring temperatures for water years 2005-2021

spring MK & SS for 797 (non-corrected)

spring_sd_mk_797 <- mk.test(spring_standard_dev_all_797$sd_2)
print(spring_sd_mk_797)
## 
##  Mann-Kendall trend test
## 
## data:  spring_standard_dev_all_797$sd_2
## z = -2.3795, n = 31, p-value = 0.01734
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##            S         varS          tau 
## -141.0000000 3461.6666667   -0.3032258
spring_sd_sens_797 <- sens.slope(spring_standard_dev_all_797$sd_2)
print(spring_sd_sens_797)
## 
##  Sen's slope
## 
## data:  spring_standard_dev_all_797$sd_2
## z = -2.3795, n = 31, p-value = 0.01734
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.07613913 -0.01255295
## sample estimates:
## Sen's slope 
## -0.04548359

Fall

Fall is split each water year in the middle of the season. This analysis splits the fall season between the preceding water year and the subsequent water year.

fall_standard_dev_all_797 <- standard_dev_797 %>%
  filter(waterDay >= 336 | waterDay <= 31) %>% 
  group_by(waterYear) %>% 
  mutate(nmbr = n())

fall_standard_dev_all_797 <- fall_standard_dev_all_797 %>% 
  #group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)

fall_standard_dev_all_797 %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1988 3.469334
1989 3.075554
1990 5.158286
1991 4.251894
1992 5.658169
1995 4.936021
1996 3.989659
1997 5.944766
1998 5.358058
1999 3.973431
2000 3.827755
2001 5.009575
2002 3.339483
2003 5.119578
2004 3.523096
2007 4.479409
2008 3.440613
2009 3.455058
2010 5.676387
2011 4.013594
2012 4.550461
2013 3.875585
2014 5.180824
2015 3.092062
2016 3.447519
2017 3.342722
2018 3.330472
2019 4.657487
2020 5.826500
2021 4.154237
2022 4.991619
ggplot(fall_standard_dev_all_797, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Non-corrected standard deviation of SNOTEL 797 average fall temperatures for water years 2005-2021. Note that the season is split by the water year.

fall MK & SS for 797 (non-corrected)

fall_sd_mk_797 <- mk.test(fall_standard_dev_all_797$sd_2)
print(fall_sd_mk_797)
## 
##  Mann-Kendall trend test
## 
## data:  fall_standard_dev_all_797$sd_2
## z = -0.50989, n = 31, p-value = 0.6101
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##             S          varS           tau 
##  -31.00000000 3461.66666667   -0.06666667
fall_sd_sens_797 <- sens.slope(fall_standard_dev_all_797$sd_2)
print(fall_sd_sens_797)
## 
##  Sen's slope
## 
## data:  fall_standard_dev_all_797$sd_2
## z = -0.50989, n = 31, p-value = 0.6101
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.05222127  0.02739725
## sample estimates:
##  Sen's slope 
## -0.007604943

Spring and Fall SD CORRECTED

Spring

spring_standard_dev_all_797_ad <- standard_dev_797_ad %>% 
  filter(waterDay >= 183 & waterDay <= 243) %>%
  group_by(waterYear) %>% 
  mutate(nmbr = n())
spring_standard_dev_all_797_ad <- spring_standard_dev_all_797_ad %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)
spring_standard_dev_all_797_ad %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1988 4.146926
1989 6.111117
1990 2.931640
1991 4.831601
1992 3.179717
1995 3.531811
1996 4.715686
1997 5.046627
1998 4.776796
1999 4.698195
2000 4.449363
2001 5.328142
2002 4.178613
2003 4.850698
2004 7.593132
2007 3.903036
2008 4.254352
2009 4.894185
2010 4.695058
2011 4.203584
2012 3.949941
2013 4.242776
2014 4.752034
2015 3.082310
2016 3.787129
2017 4.003553
2018 3.998070
2019 3.428151
2020 4.110158
2021 3.586207
2022 4.371673
ggplot(spring_standard_dev_all_797_ad, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Morrisey-corrected standard deviation of SNOTEL 797 average spring temperatures for water years 1986-2021

spring MK & SS 797 (corrected)

spring_sd_mk_797_ad <- mk.test(spring_standard_dev_all_797_ad$sd_2)
print(spring_sd_mk_797_ad)
## 
##  Mann-Kendall trend test
## 
## data:  spring_standard_dev_all_797_ad$sd_2
## z = -1.6656, n = 31, p-value = 0.09578
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##            S         varS          tau 
##  -99.0000000 3461.6666667   -0.2129032
spring_sd_sens_797_ad <- sens.slope(spring_standard_dev_all_797_ad$sd_2)
print(spring_sd_sens_797_ad)
## 
##  Sen's slope
## 
## data:  spring_standard_dev_all_797_ad$sd_2
## z = -1.6656, n = 31, p-value = 0.09578
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.055599354  0.004564271
## sample estimates:
## Sen's slope 
## -0.02858398

Fall

fall_standard_dev_all_797_ad <- standard_dev_797_ad %>% 
  filter(waterDay >= 336 | waterDay <= 31) %>%
  group_by(waterYear) %>% 
  mutate(nmbr = n())
fall_standard_dev_all_797_ad <- fall_standard_dev_all_797_ad %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)
fall_standard_dev_all_797_ad %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1988 3.176439
1989 2.805960
1990 4.742345
1991 3.894049
1992 5.122097
1995 4.525290
1996 3.668729
1997 5.518119
1998 4.959803
1999 3.662819
2000 3.496075
2001 4.605293
2002 3.050711
2003 4.714205
2004 3.217726
2007 4.479395
2008 3.441355
2009 3.455796
2010 5.678702
2011 4.015037
2012 4.551011
2013 3.875485
2014 5.180389
2015 3.092875
2016 3.447852
2017 3.341428
2018 3.330865
2019 4.657659
2020 5.827947
2021 4.152856
2022 4.991814
ggplot(fall_standard_dev_all_797_ad, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Morrisey-corrected standard deviation of SNOTEL 797 average fall temperatures for water years 1986-2021. Note that the fall season is split by the water year.

fall MK & SS 797 (corrected)

fall_sd_mk_797_ad <- mk.test(fall_standard_dev_all_797_ad$sd_2)
print(fall_sd_mk_797_ad)
## 
##  Mann-Kendall trend test
## 
## data:  fall_standard_dev_all_797_ad$sd_2
## z = 0.37392, n = 31, p-value = 0.7085
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##            S         varS          tau 
## 2.300000e+01 3.461667e+03 4.946237e-02
fall_sd_sens_797_ad <- sens.slope(fall_standard_dev_all_797_ad$sd_2)
print(fall_sd_sens_797_ad)
## 
##  Sen's slope
## 
## data:  fall_standard_dev_all_797_ad$sd_2
## z = 0.37392, n = 31, p-value = 0.7085
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.02587782  0.04709189
## sample estimates:
## Sen's slope 
## 0.008909618

Upper Rio Grande 839

Oyler -> Morrisey 5/26/2004

snotel_839 <- SNOTEL_san_juan_Area %>% 
  filter(site_id == "839")
#str(snotel_839) # check the date, usually a character.  

snotel_839$Date <- as.Date(snotel_839$date) #change date from character to date format, capitalize to work with Water year functon from NWIS.

#THIS WILL CHANGE FOR EACH STATION
snotel_839_clean <- snotel_839 %>% # filter for the timeframe
  filter(Date >= "1979-10-01" & Date <= "2022-09-30") %>%
  #filter(temperature_mean >= -30 & temperature_mean <= 20) %>% # removing outliers   
  addWaterYear() %>% 
  mutate(daymonth = format(as.Date(Date), "%d-%m")) %>% 
  na.omit()

#adding water day using difftime (SUPER COOL. example from [this](https://stackoverflow.com/questions/48123049/create-day-index-based-on-water-year))

snotel_839_clean <- snotel_839_clean %>% 
  group_by(waterYear)%>% 
  mutate(waterDay = (as.integer(difftime(Date, ymd(paste0(waterYear - 1 ,'-09-30')), units = "days"))))
# Check for outliers

ggplot(snotel_839_clean, aes(x = Date, y = temperature_mean)) +
  geom_point() + #lwd = 2) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('Daily temperature (°C)') + 
  xlab('Date')

snotel_839_clean <- snotel_839_clean %>% 
  mutate(temp_diff = abs(temperature_min - temperature_max)) %>% 
  filter(temperature_mean > -40) %>% 
  filter(temperature_mean < 25)
ggplot(snotel_839_clean, aes(x = Date, y = temp_diff)) + 
  geom_point() + #lwd = 2) +
  theme_few() +
  #geom_smooth(method = "lm", se=FALSE) +
  ylab('Daily temperature varience (°C)') + 
  xlab('Date')

Per Steven’s advice: :If there are more than 15 missing days, then…remove that year”

# filtering for temperature anomalies
#snotel_839_cull_count <- snotel_839_clean %>% 
#  filter(temperature_min > -40) %>% 
#  count(waterYear)

#snotel_839_cull_count

# filtering for too few observations in a year
snotel_839_cull_count_days <- snotel_839_clean %>% 
  group_by(waterYear) %>% 
  count(waterYear) %>% 
  filter(n < 350)

snotel_839_cull_count_days
## # A tibble: 5 x 2
## # Groups:   waterYear [5]
##   waterYear     n
##       <dbl> <int>
## 1      1994   338
## 2      2004   330
## 3      2012   339
## 4      2014   313
## 5      2016   347

1994, 2004, 2012, 2014, 2016 need to be culled.

snotel_839_clean_culled <- snotel_839_clean %>% 
  filter(waterYear != "1994" & waterYear != "2004" & waterYear != "2012" & waterYear != "2014" & waterYear != "2016")# & waterYear != "2021" & waterYear != "2022") & waterYear != "2014") #%>% 
  #filter(temperature_mean > -49)

ggplot(snotel_839_clean_culled, aes(x = Date, y = temp_diff)) + 
  geom_point() + #lwd = 2) +
  theme_few() +
  #geom_smooth(method = "lm", se=FALSE) +
  ylab('Daily temperature varience (°C)') + 
  xlab('Date')

ggplot(snotel_839_clean_culled, aes(x = Date, y = temperature_mean)) + 
  geom_point() + #lwd = 2) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('Daily temperature (°C)') + 
  xlab('Date')

temp_839_xts <- xts(snotel_839_clean_culled$temperature_mean, order.by = snotel_839_clean_culled$Date)

dygraph(temp_839_xts) %>%
  dyAxis("y", label = "Daily mean temperature (°C)") 
#snotel_839_clean_culled <- snotel_839_clean_culled %>% 
#  filter(temperature_mean < 19.3)

temp_839_xts <- xts(snotel_839_clean_culled$temperature_mean, order.by = snotel_839_clean_culled$Date)

dygraph(temp_839_xts) %>%
  dyAxis("y", label = "Daily mean temperature (°C)") 

Upper Rio Grande 839

Oyler -> Morrisey 5/26/2004

snotel_839_adjusted <- snotel_839_clean_culled %>%
  mutate(temp_ad = if_else(Date < "2004-05-26", ((5.3*10^(-7))*(temperature_mean^(4))+(3.72*10^(-5))*(temperature_mean^(3))-(2.16*10^(-3))*(temperature_mean^(2))-(7.32*10^(-2))*(temperature_mean)+1.37)+temperature_mean, temperature_mean))

Non-corrected

839 Detrended

#using the clean culled df:

#average water year temperature

yearly_wy_aver_839 <- snotel_839_adjusted %>% 
  group_by(waterYear) %>% 
  mutate(aver_ann_temp = mean(temperature_mean))

#Average temperature by day for all water years:

daily_wy_aver_839 <- yearly_wy_aver_839 %>% 
  group_by(daymonth) %>% 
  mutate(aver_day_temp = mean(aver_ann_temp))

#average mean temperature by day for the period of record:

daily_wy_aver_839 <- daily_wy_aver_839 %>% 
  group_by(daymonth) %>% 
  mutate(all_ave_temp = mean(daily_wy_aver_839$aver_day_temp))

# try to show all years as means. 
daily_wy_aver2_839 <-daily_wy_aver_839 %>% 
  group_by(waterDay) %>%
  mutate(date_temp = mean(temperature_mean))
  

daily_wy_aver2_839$date_temp <- signif(daily_wy_aver2_839$date_temp,3) #reduce the sig figs


ggplot(daily_wy_aver2_839, aes(x = waterDay, y = date_temp))+
  geom_line(size= 0.7) +
  theme_few() +
  ylab('Average Daily temperature (°C)') + 
  xlab('Day of water year')

839 SD

standard_dev_839 <- daily_wy_aver_839 %>% 
  group_by(waterYear) %>% 
  mutate(residual = (all_ave_temp-aver_ann_temp)+temperature_mean-aver_day_temp) %>% 
  mutate(deviation = abs(residual-lag(residual)))

standard_dev_all_839 <- standard_dev_839 %>% 
  group_by(waterYear) %>% 
  mutate(nmbr = n())

standard_dev_all_839 <- standard_dev_all_839 %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)

standard_dev_all_839 %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1987 9.000013
1988 9.231875
1989 9.553651
1990 8.539684
1991 9.095321
1992 8.840589
1993 9.034837
1995 8.477482
1996 8.374844
1997 8.635328
1998 9.151866
1999 7.826807
2000 8.411485
2001 9.307564
2002 9.394376
2003 8.653297
2005 8.284320
2006 7.873798
2007 8.375674
2008 8.874800
2009 7.572710
2010 9.043721
2011 8.610385
2013 9.013859
2015 7.623354
2017 7.852672
2018 7.363181
2019 8.357738
2020 8.830386
2021 8.642675
2022 7.975856
ggplot(standard_dev_all_839, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Non-corrected standard deviation of SNOTEL 839 average temperatures for water years 2005-2021

MK & SS for 839 (non-corrected)

sd_mk_839 <- mk.test(standard_dev_all_839$sd_2)
print(sd_mk_839)
## 
##  Mann-Kendall trend test
## 
## data:  standard_dev_all_839$sd_2
## z = -2.5495, n = 31, p-value = 0.01079
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##            S         varS          tau 
## -151.0000000 3461.6666667   -0.3247312
sd_sens_839 <- sens.slope(standard_dev_all_839$sd_2)
print(sd_sens_839)
## 
##  Sen's slope
## 
## data:  standard_dev_all_839$sd_2
## z = -2.5495, n = 31, p-value = 0.01079
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.051315272 -0.008246409
## sample estimates:
## Sen's slope 
## -0.03122783

Corrected

839 Detrended (corrected)

#using the clean culled df:
#average water year temperature
yearly_wy_aver_839_ad <- snotel_839_adjusted %>% 
  group_by(waterYear) %>% 
  mutate(aver_ann_temp_ad = mean(temp_ad))
#Average temperature by day for all water years:
daily_wy_aver_839_ad <- yearly_wy_aver_839_ad %>% 
  group_by(daymonth) %>% 
  mutate(aver_day_temp_ad = mean(aver_ann_temp_ad))
#average mean temperature by day for the period of record:
daily_wy_aver_839_ad <- daily_wy_aver_839_ad %>% 
  group_by(daymonth) %>% 
  mutate(all_ave_temp_ad = mean(daily_wy_aver_839_ad$aver_day_temp_ad))
# try to show all years as means. 
daily_wy_aver2_839_ad <-daily_wy_aver_839_ad %>% 
  group_by(waterDay) %>%
  mutate(date_temp_ad = mean(temp_ad))
  
daily_wy_aver2_839_ad$date_temp_ad <- signif(daily_wy_aver2_839_ad$date_temp_ad,3) #reduce the sig figs
ggplot(daily_wy_aver2_839_ad, aes(x = waterDay, y = date_temp_ad))+
  geom_line(size= 0.7) +
  theme_few() +
  ylab('Average Daily temperature (°C)') + 
  xlab('Day of water year')

839 SS (corrected)

standard_dev_839_ad <- daily_wy_aver_839_ad %>% 
  group_by(waterYear) %>% 
  #filter(waterYear >= 1987 & waterYear <= 2021) %>% 
  mutate(residual = (all_ave_temp_ad-aver_ann_temp_ad)+temp_ad-aver_day_temp_ad) %>% 
  mutate(deviation = abs(residual-lag(residual)))
standard_dev_all_839_ad <- standard_dev_839_ad %>% 
  group_by(waterYear) %>% 
  mutate(nmbr = n())
standard_dev_all_839_ad <- standard_dev_all_839_ad %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)
standard_dev_all_839_ad %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1987 8.404486
1988 8.657820
1989 8.999163
1990 7.974877
1991 8.538551
1992 8.275130
1993 8.430766
1995 7.896968
1996 7.767745
1997 8.045426
1998 8.511594
1999 7.265049
2000 7.783278
2001 8.666438
2002 8.721243
2003 8.026530
2005 8.284037
2006 7.873931
2007 8.375662
2008 8.875360
2009 7.573403
2010 9.044246
2011 8.610915
2013 9.013498
2015 7.624141
2017 7.852753
2018 7.363589
2019 8.358178
2020 8.831049
2021 8.643116
2022 7.976653
ggplot(standard_dev_all_839_ad, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Morrisey-corrected standard deviation of SNOTEL 839 average temperatures for water years 1986-2021

MK & SS 839 (corrected)

sd_mk_839_ad <- mk.test(standard_dev_all_839_ad$sd_2)
print(sd_mk_839_ad)
## 
##  Mann-Kendall trend test
## 
## data:  standard_dev_all_839_ad$sd_2
## z = -0.16996, n = 31, p-value = 0.865
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##             S          varS           tau 
##  -11.00000000 3461.66666667   -0.02365591
sd_sens_839_ad <- sens.slope(standard_dev_all_839_ad$sd_2)
print(sd_sens_839_ad)
## 
##  Sen's slope
## 
## data:  standard_dev_all_839_ad$sd_2
## z = -0.16996, n = 31, p-value = 0.865
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.02519708  0.02245395
## sample estimates:
##  Sen's slope 
## -0.002233571

Summer and Winter SD NOT-CORRECTED

Summer

summer_standard_dev_all_839 <- standard_dev_839 %>%
  filter(waterDay >= 244 & waterDay <= 335) %>%
  group_by(waterYear) %>% 
  mutate(nmbr = n())

summer_standard_dev_all_839 <- summer_standard_dev_all_839 %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)

summer_standard_dev_all_839 %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1987 2.339645
1988 2.409039
1989 3.000858
1990 2.873313
1991 2.515342
1992 2.864531
1993 2.899106
1995 2.810444
1996 2.024826
1997 2.150453
1998 2.670019
1999 2.391108
2000 1.660533
2001 2.194305
2002 2.195636
2003 5.141657
2005 2.571311
2006 1.780020
2007 2.008229
2008 1.893666
2009 2.494618
2010 2.130592
2011 1.651068
2013 1.798254
2015 2.039987
2017 1.785569
2018 1.687691
2019 2.071325
2020 1.899239
2021 1.936877
2022 1.802188
ggplot(summer_standard_dev_all_839, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Non-corrected standard deviation of SNOTEL 839 average summer temperatures for water years 2005-2021

summer MK & SS for 839 (non-corrected)

summer_sd_mk_839 <- mk.test(summer_standard_dev_all_839$sd_2)
print(summer_sd_mk_839)
## 
##  Mann-Kendall trend test
## 
## data:  summer_standard_dev_all_839$sd_2
## z = -3.6372, n = 31, p-value = 0.0002756
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##            S         varS          tau 
## -215.0000000 3461.6666667   -0.4623656
summer_sd_sens_839 <- sens.slope(summer_standard_dev_all_839$sd_2)
print(summer_sd_sens_839)
## 
##  Sen's slope
## 
## data:  summer_standard_dev_all_839$sd_2
## z = -3.6372, n = 31, p-value = 0.0002756
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.04383721 -0.01789452
## sample estimates:
## Sen's slope 
## -0.03129896

Winter

winter_standard_dev_all_839 <- standard_dev_839 %>%
  filter(waterDay >= 32 & waterDay <= 182) %>%
  group_by(waterYear) %>% 
  mutate(nmbr = n())

winter_standard_dev_all_839 <- winter_standard_dev_all_839 %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)

winter_standard_dev_all_839 %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1987 4.398805
1988 5.590658
1989 6.853499
1990 5.272310
1991 5.213793
1992 5.050047
1993 4.722721
1995 5.134365
1996 4.847138
1997 5.056218
1998 4.784267
1999 4.600428
2000 4.565157
2001 4.566478
2002 5.212259
2003 4.381878
2005 4.302631
2006 4.639049
2007 5.599134
2008 6.135623
2009 4.558676
2010 4.897715
2011 5.631610
2013 5.742855
2015 5.016585
2017 5.707411
2018 4.346846
2019 4.407444
2020 5.155251
2021 4.616505
2022 4.708981
ggplot(winter_standard_dev_all_839, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Non-corrected standard deviation of SNOTEL 839 average winter temperatures for water years 2005-2021

winter MK & SS for 839 (non-corrected)

winter_sd_mk_839 <- mk.test(winter_standard_dev_all_839$sd_2)
print(winter_sd_mk_839)
## 
##  Mann-Kendall trend test
## 
## data:  winter_standard_dev_all_839$sd_2
## z = -0.91781, n = 31, p-value = 0.3587
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##            S         varS          tau 
##  -55.0000000 3461.6666667   -0.1182796
winter_sd_sens_839 <- sens.slope(winter_standard_dev_all_839$sd_2)
print(winter_sd_sens_839)
## 
##  Sen's slope
## 
## data:  winter_standard_dev_all_839$sd_2
## z = -0.91781, n = 31, p-value = 0.3587
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.03527040  0.01166625
## sample estimates:
## Sen's slope 
## -0.01171751

Summer and Winter SD CORRECTED

Summer

summer_standard_dev_all_839_ad <- standard_dev_839_ad %>% 
  filter(waterDay >= 244 & waterDay <= 335) %>%
  group_by(waterYear) %>% 
  mutate(nmbr = n())
summer_standard_dev_all_839_ad <- summer_standard_dev_all_839_ad %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)
summer_standard_dev_all_839_ad %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1987 2.100721
1988 2.165432
1989 2.694263
1990 2.586843
1991 2.264622
1992 2.577564
1993 2.603045
1995 2.521410
1996 1.812342
1997 1.930230
1998 2.393978
1999 2.149070
2000 1.485761
2001 1.966973
2002 1.964327
2003 4.629268
2005 2.570019
2006 1.778567
2007 2.008120
2008 1.893140
2009 2.494537
2010 2.130945
2011 1.651218
2013 1.797667
2015 2.039573
2017 1.785650
2018 1.687040
2019 2.070803
2020 1.898818
2021 1.936581
2022 1.802555
ggplot(summer_standard_dev_all_839_ad, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Morrisey-corrected standard deviation of SNOTEL 839 average summer temperatures for water years 1986-2021

summer MK & SS 839 (corrected)

summer_sd_mk_839_ad <- mk.test(summer_standard_dev_all_839_ad$sd_2)
print(summer_sd_mk_839_ad)
## 
##  Mann-Kendall trend test
## 
## data:  summer_standard_dev_all_839_ad$sd_2
## z = -2.8894, n = 31, p-value = 0.00386
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##            S         varS          tau 
## -171.0000000 3461.6666667   -0.3677419
summer_sd_sens_839_ad <- sens.slope(summer_standard_dev_all_839_ad$sd_2)
print(summer_sd_sens_839_ad)
## 
##  Sen's slope
## 
## data:  summer_standard_dev_all_839_ad$sd_2
## z = -2.8894, n = 31, p-value = 0.00386
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.031254569 -0.005659981
## sample estimates:
## Sen's slope 
## -0.01895022

Winter

winter_standard_dev_all_839_ad <- standard_dev_839_ad %>% 
  filter(waterDay >= 32 & waterDay <= 182) %>%
  group_by(waterYear) %>% 
  mutate(nmbr = n())
winter_standard_dev_all_839_ad <- winter_standard_dev_all_839_ad %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)
winter_standard_dev_all_839_ad %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1987 4.287106
1988 5.464765
1989 6.712024
1990 5.114028
1991 5.120770
1992 4.913951
1993 4.586285
1995 4.965760
1996 4.676376
1997 4.889709
1998 4.616778
1999 4.426756
2000 4.386454
2001 4.434810
2002 5.014547
2003 4.228870
2005 4.301491
2006 4.640098
2007 5.598865
2008 6.136443
2009 4.560635
2010 4.898822
2011 5.633033
2013 5.744435
2015 5.018158
2017 5.707307
2018 4.347866
2019 4.408918
2020 5.156412
2021 4.617938
2022 4.711537
ggplot(winter_standard_dev_all_839_ad, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Morrisey-corrected standard deviation of SNOTEL 839 average winter temperatures for water years 1986-2021

winter MK & SS 839 (corrected)

winter_sd_mk_839_ad <- mk.test(winter_standard_dev_all_839_ad$sd_2)
print(winter_sd_mk_839_ad)
## 
##  Mann-Kendall trend test
## 
## data:  winter_standard_dev_all_839_ad$sd_2
## z = -0.10198, n = 31, p-value = 0.9188
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##             S          varS           tau 
##   -7.00000000 3461.66666667   -0.01505376
winter_sd_sens_839_ad <- sens.slope(winter_standard_dev_all_839_ad$sd_2)
print(winter_sd_sens_839_ad)
## 
##  Sen's slope
## 
## data:  winter_standard_dev_all_839_ad$sd_2
## z = -0.10198, n = 31, p-value = 0.9188
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.02991581  0.01806017
## sample estimates:
## Sen's slope 
## -0.00184666

Spring and Fall SD NOT-CORRECTED

Spring

spring_standard_dev_all_839 <- standard_dev_839 %>%
  filter(waterDay >= 183 & waterDay <= 243) %>%
  group_by(waterYear) %>% 
  mutate(nmbr = n())

spring_standard_dev_all_839 <- spring_standard_dev_all_839 %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)

spring_standard_dev_all_839 %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1987 3.610657
1988 4.402903
1989 3.833645
1990 2.705790
1991 4.780308
1992 3.079578
1993 3.877081
1995 3.404194
1996 4.958142
1997 4.880219
1998 4.651256
1999 4.731681
2000 4.440642
2001 4.265454
2002 3.135824
2003 4.442203
2005 4.201413
2006 3.305735
2007 3.234636
2008 3.845079
2009 4.355085
2010 4.227429
2011 3.893810
2013 3.782819
2015 2.515428
2017 3.622898
2018 3.480007
2019 2.776526
2020 3.699330
2021 3.237320
2022 4.029325
ggplot(spring_standard_dev_all_839, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Non-corrected standard deviation of SNOTEL 839 average spring temperatures for water years 2005-2021

spring MK & SS for 839 (non-corrected)

spring_sd_mk_839 <- mk.test(spring_standard_dev_all_839$sd_2)
print(spring_sd_mk_839)
## 
##  Mann-Kendall trend test
## 
## data:  spring_standard_dev_all_839$sd_2
## z = -1.6996, n = 31, p-value = 0.0892
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##            S         varS          tau 
## -101.0000000 3461.6666667   -0.2172043
spring_sd_sens_839 <- sens.slope(spring_standard_dev_all_839$sd_2)
print(spring_sd_sens_839)
## 
##  Sen's slope
## 
## data:  spring_standard_dev_all_839$sd_2
## z = -1.6996, n = 31, p-value = 0.0892
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.059807134  0.003008293
## sample estimates:
## Sen's slope 
##  -0.0307368

Fall

Fall is split each water year in the middle of the season. This analysis splits the fall season between the preceding water year and the subsequent water year.

fall_standard_dev_all_839 <- standard_dev_839 %>%
  filter(waterDay >= 336 | waterDay <= 31) %>% 
  group_by(waterYear) %>% 
  mutate(nmbr = n())

fall_standard_dev_all_839 <- fall_standard_dev_all_839 %>% 
  #group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)

fall_standard_dev_all_839 %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1987 3.526403
1988 3.382711
1989 2.662548
1990 4.436162
1991 3.745685
1992 4.073137
1993 3.244904
1995 4.362266
1996 3.624605
1997 5.335354
1998 5.236951
1999 3.750822
2000 3.795008
2001 4.146745
2002 3.222176
2003 4.124271
2005 4.189369
2006 2.781917
2007 4.292954
2008 3.174320
2009 3.293799
2010 5.286309
2011 3.687951
2013 3.983378
2015 2.982585
2017 3.050361
2018 3.028875
2019 4.402357
2020 5.430847
2021 3.987308
2022 4.497720
ggplot(fall_standard_dev_all_839, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Non-corrected standard deviation of SNOTEL 839 average fall temperatures for water years 2005-2021. Note that the season is split by the water year.

fall MK & SS for 839 (non-corrected)

fall_sd_mk_839 <- mk.test(fall_standard_dev_all_839$sd_2)
print(fall_sd_mk_839)
## 
##  Mann-Kendall trend test
## 
## data:  fall_standard_dev_all_839$sd_2
## z = 0.57788, n = 31, p-value = 0.5633
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##            S         varS          tau 
## 3.500000e+01 3.461667e+03 7.526882e-02
fall_sd_sens_839 <- sens.slope(fall_standard_dev_all_839$sd_2)
print(fall_sd_sens_839)
## 
##  Sen's slope
## 
## data:  fall_standard_dev_all_839$sd_2
## z = 0.57788, n = 31, p-value = 0.5633
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.02148640  0.03985786
## sample estimates:
## Sen's slope 
##  0.01131176

Spring and Fall SD CORRECTED

Spring

spring_standard_dev_all_839_ad <- standard_dev_839_ad %>% 
  filter(waterDay >= 183 & waterDay <= 243) %>%
  group_by(waterYear) %>% 
  mutate(nmbr = n())
spring_standard_dev_all_839_ad <- spring_standard_dev_all_839_ad %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)
spring_standard_dev_all_839_ad %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1987 3.342757
1988 4.045006
1989 3.492194
1990 2.470203
1991 4.450793
1992 2.812794
1993 3.548800
1995 3.145748
1996 4.522040
1997 4.516174
1998 4.277480
1999 4.379855
2000 4.041036
2001 3.901260
2002 2.840141
2003 4.059453
2005 4.201413
2006 3.305735
2007 3.234636
2008 3.845079
2009 4.355085
2010 4.227429
2011 3.893810
2013 3.782819
2015 2.515428
2017 3.622898
2018 3.480007
2019 2.776526
2020 3.699330
2021 3.237320
2022 4.029325
ggplot(spring_standard_dev_all_839_ad, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Morrisey-corrected standard deviation of SNOTEL 839 average spring temperatures for water years 1986-2021

spring MK & SS 839 (corrected)

spring_sd_mk_839_ad <- mk.test(spring_standard_dev_all_839_ad$sd_2)
print(spring_sd_mk_839_ad)
## 
##  Mann-Kendall trend test
## 
## data:  spring_standard_dev_all_839_ad$sd_2
## z = -0.88381, n = 31, p-value = 0.3768
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##            S         varS          tau 
##  -53.0000000 3461.6666667   -0.1139785
spring_sd_sens_839_ad <- sens.slope(spring_standard_dev_all_839_ad$sd_2)
print(spring_sd_sens_839_ad)
## 
##  Sen's slope
## 
## data:  spring_standard_dev_all_839_ad$sd_2
## z = -0.88381, n = 31, p-value = 0.3768
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.03805084  0.01781170
## sample estimates:
## Sen's slope 
## -0.01240776

Fall

fall_standard_dev_all_839_ad <- standard_dev_839_ad %>% 
  filter(waterDay >= 336 | waterDay <= 31) %>%
  group_by(waterYear) %>% 
  mutate(nmbr = n())
fall_standard_dev_all_839_ad <- fall_standard_dev_all_839_ad %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)
fall_standard_dev_all_839_ad %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1987 3.235641
1988 3.079022
1989 2.416424
1990 4.055726
1991 3.436007
1992 3.753620
1993 2.959169
1995 3.970281
1996 3.301350
1997 4.907239
1998 4.803570
1999 3.424112
2000 3.440029
2001 3.782416
2002 2.919789
2003 3.766713
2005 4.187849
2006 2.781149
2007 4.292325
2008 3.173017
2009 3.294609
2010 5.287997
2011 3.688079
2013 3.981277
2015 2.983605
2017 3.049157
2018 3.028348
2019 4.402351
2020 5.430277
2021 3.985507
2022 4.496885
ggplot(fall_standard_dev_all_839_ad, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Morrisey-corrected standard deviation of SNOTEL 839 average fall temperatures for water years 1986-2021. Note that the fall season is split by the water year.

fall MK & SS 839 (corrected)

fall_sd_mk_839_ad <- mk.test(fall_standard_dev_all_839_ad$sd_2)
print(fall_sd_mk_839_ad)
## 
##  Mann-Kendall trend test
## 
## data:  fall_standard_dev_all_839_ad$sd_2
## z = 1.4957, n = 31, p-value = 0.1347
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##            S         varS          tau 
##   89.0000000 3461.6666667    0.1913978
fall_sd_sens_839_ad <- sens.slope(fall_standard_dev_all_839_ad$sd_2)
print(fall_sd_sens_839_ad)
## 
##  Sen's slope
## 
## data:  fall_standard_dev_all_839_ad$sd_2
## z = 1.4957, n = 31, p-value = 0.1347
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.008837386  0.052237872
## sample estimates:
## Sen's slope 
##    0.024805

Upper San Juan 840

Morrisey 4/7/2004

snotel_840 <- SNOTEL_san_juan_Area %>% 
  filter(site_id == "840")
#str(snotel_840) # check the date, usually a character.  

snotel_840$Date <- as.Date(snotel_840$date) #change date from character to date format, capitalize to work with Water year functon from NWIS.

#THIS WILL CHANGE FOR EACH STATION
snotel_840_clean <- snotel_840 %>% # filter for the timeframe
  filter(Date >= "1979-10-01" & Date <= "2022-09-30") %>%
  #filter(temperature_mean >= -30 & temperature_mean <= 20) %>% # removing outliers   
  addWaterYear() %>% 
  mutate(daymonth = format(as.Date(Date), "%d-%m")) %>% 
  na.omit()

#adding water day using difftime (SUPER COOL. example from [this](https://stackoverflow.com/questions/48123049/create-day-index-based-on-water-year))

snotel_840_clean <- snotel_840_clean %>% 
  group_by(waterYear)%>% 
  mutate(waterDay = (as.integer(difftime(Date, ymd(paste0(waterYear - 1 ,'-09-30')), units = "days"))))
# Check for outliers

ggplot(snotel_840_clean, aes(x = Date, y = temperature_mean)) +
  geom_point() + #lwd = 2) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('Daily temperature (°C)') + 
  xlab('Date')

snotel_840_clean <- snotel_840_clean %>% 
  mutate(temp_diff = abs(temperature_min - temperature_max)) %>% 
  filter(temperature_mean > -40) %>% 
  filter(temperature_mean < 25)
ggplot(snotel_840_clean, aes(x = Date, y = temp_diff)) + 
  geom_point() + #lwd = 2) +
  theme_few() +
  #geom_smooth(method = "lm", se=FALSE) +
  ylab('Daily temperature varience (°C)') + 
  xlab('Date')

Per Steven’s advice: :If there are more than 15 missing days, then…remove that year”

# filtering for temperature anomalies
#snotel_840_cull_count <- snotel_840_clean %>% 
#  filter(temperature_min > -40) %>% 
#  count(waterYear)

#snotel_840_cull_count

# filtering for too few observations in a year
snotel_840_cull_count_days <- snotel_840_clean %>% 
  group_by(waterYear) %>% 
  count(waterYear) %>% 
  filter(n < 350)

snotel_840_cull_count_days
## # A tibble: 11 x 2
## # Groups:   waterYear [11]
##    waterYear     n
##        <dbl> <int>
##  1      1980   310
##  2      1981   274
##  3      1982     1
##  4      1983   318
##  5      1984   322
##  6      1985   275
##  7      1993   349
##  8      1994   345
##  9      2005   309
## 10      2006   325
## 11      2013   314

1980, 1981, 1982, 1983, 1984, 1985, 1993, 1994, 2005, 2006, 2013 need to be culled.

snotel_840_clean_culled <- snotel_840_clean %>% 
  filter(waterYear >= "1986" & waterYear != "1993" & waterYear != "1994" & waterYear != "2005" & waterYear != "2006" & waterYear != "2013")# & waterYear != "2022") & waterYear != "2014") #%>% 
  #filter(temperature_mean > -49)

ggplot(snotel_840_clean_culled, aes(x = Date, y = temp_diff)) + 
  geom_point() + #lwd = 2) +
  theme_few() +
  #geom_smooth(method = "lm", se=FALSE) +
  ylab('Daily temperature varience (°C)') + 
  xlab('Date')

ggplot(snotel_840_clean_culled, aes(x = Date, y = temperature_mean)) + 
  geom_point() + #lwd = 2) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('Daily temperature (°C)') + 
  xlab('Date')

temp_840_xts <- xts(snotel_840_clean_culled$temperature_mean, order.by = snotel_840_clean_culled$Date)

dygraph(temp_840_xts) %>%
  dyAxis("y", label = "Daily mean temperature (°C)") 
#snotel_840_clean_culled <- snotel_840_clean_culled %>% 
#  filter(temperature_mean < 19.3)

temp_840_xts <- xts(snotel_840_clean_culled$temperature_mean, order.by = snotel_840_clean_culled$Date)

dygraph(temp_840_xts) %>%
  dyAxis("y", label = "Daily mean temperature (°C)") 

Upper San Juan 840

Morrisey 4/7/2004

snotel_840_adjusted <- snotel_840_clean_culled %>%
  mutate(temp_ad = if_else(Date < "2004-04-07", ((5.3*10^(-7))*(temperature_mean^(4))+(3.72*10^(-5))*(temperature_mean^(3))-(2.16*10^(-3))*(temperature_mean^(2))-(7.32*10^(-2))*(temperature_mean)+1.37)+temperature_mean, temperature_mean))

Non-corrected

840 Detrended

#using the clean culled df:

#average water year temperature

yearly_wy_aver_840 <- snotel_840_adjusted %>% 
  group_by(waterYear) %>% 
  mutate(aver_ann_temp = mean(temperature_mean))

#Average temperature by day for all water years:

daily_wy_aver_840 <- yearly_wy_aver_840 %>% 
  group_by(daymonth) %>% 
  mutate(aver_day_temp = mean(aver_ann_temp))

#average mean temperature by day for the period of record:

daily_wy_aver_840 <- daily_wy_aver_840 %>% 
  group_by(daymonth) %>% 
  mutate(all_ave_temp = mean(daily_wy_aver_840$aver_day_temp))

# try to show all years as means. 
daily_wy_aver2_840 <-daily_wy_aver_840 %>% 
  group_by(waterDay) %>%
  mutate(date_temp = mean(temperature_mean))
  

daily_wy_aver2_840$date_temp <- signif(daily_wy_aver2_840$date_temp,3) #reduce the sig figs


ggplot(daily_wy_aver2_840, aes(x = waterDay, y = date_temp))+
  geom_line(size= 0.7) +
  theme_few() +
  ylab('Average Daily temperature (°C)') + 
  xlab('Day of water year')

840 SD

standard_dev_840 <- daily_wy_aver_840 %>% 
  group_by(waterYear) %>% 
  mutate(residual = (all_ave_temp-aver_ann_temp)+temperature_mean-aver_day_temp) %>% 
  mutate(deviation = abs(residual-lag(residual)))

standard_dev_all_840 <- standard_dev_840 %>% 
  group_by(waterYear) %>% 
  mutate(nmbr = n())

standard_dev_all_840 <- standard_dev_all_840 %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)

standard_dev_all_840 %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1986 7.232619
1987 7.739156
1988 8.527104
1989 8.409877
1990 7.857130
1991 8.153466
1992 7.489499
1995 7.461187
1996 7.863786
1997 7.870552
1998 8.397044
1999 7.262936
2000 7.859027
2001 8.336002
2002 8.619541
2003 8.032941
2004 8.221773
2007 7.731123
2008 7.978427
2009 7.095790
2010 8.100698
2011 7.956902
2012 7.805592
2014 7.587053
2015 6.894972
2016 7.701017
2017 7.249233
2018 7.180902
2019 7.751539
2020 7.888215
2021 7.886812
2022 7.530559
ggplot(standard_dev_all_840, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Non-corrected standard deviation of SNOTEL 840 average temperatures for water years 2005-2021

MK & SS for 840 (non-corrected)

sd_mk_840 <- mk.test(standard_dev_all_840$sd_2)
print(sd_mk_840)
## 
##  Mann-Kendall trend test
## 
## data:  standard_dev_all_840$sd_2
## z = -1.5406, n = 32, p-value = 0.1234
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##            S         varS          tau 
##  -96.0000000 3802.6666667   -0.1935484
sd_sens_840 <- sens.slope(standard_dev_all_840$sd_2)
print(sd_sens_840)
## 
##  Sen's slope
## 
## data:  standard_dev_all_840$sd_2
## z = -1.5406, n = 32, p-value = 0.1234
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.031404215  0.001716915
## sample estimates:
## Sen's slope 
##  -0.0141416

Corrected

840 Detrended (corrected)

#using the clean culled df:
#average water year temperature
yearly_wy_aver_840_ad <- snotel_840_adjusted %>% 
  group_by(waterYear) %>% 
  mutate(aver_ann_temp_ad = mean(temp_ad))
#Average temperature by day for all water years:
daily_wy_aver_840_ad <- yearly_wy_aver_840_ad %>% 
  group_by(daymonth) %>% 
  mutate(aver_day_temp_ad = mean(aver_ann_temp_ad))
#average mean temperature by day for the period of record:
daily_wy_aver_840_ad <- daily_wy_aver_840_ad %>% 
  group_by(daymonth) %>% 
  mutate(all_ave_temp_ad = mean(daily_wy_aver_840_ad$aver_day_temp_ad))
# try to show all years as means. 
daily_wy_aver2_840_ad <-daily_wy_aver_840_ad %>% 
  group_by(waterDay) %>%
  mutate(date_temp_ad = mean(temp_ad))
  
daily_wy_aver2_840_ad$date_temp_ad <- signif(daily_wy_aver2_840_ad$date_temp_ad,3) #reduce the sig figs
ggplot(daily_wy_aver2_840_ad, aes(x = waterDay, y = date_temp_ad))+
  geom_line(size= 0.7) +
  theme_few() +
  ylab('Average Daily temperature (°C)') + 
  xlab('Day of water year')

840 SS (corrected)

standard_dev_840_ad <- daily_wy_aver_840_ad %>% 
  group_by(waterYear) %>% 
  #filter(waterYear >= 1987 & waterYear <= 2021) %>% 
  mutate(residual = (all_ave_temp_ad-aver_ann_temp_ad)+temp_ad-aver_day_temp_ad) %>% 
  mutate(deviation = abs(residual-lag(residual)))
standard_dev_all_840_ad <- standard_dev_840_ad %>% 
  group_by(waterYear) %>% 
  mutate(nmbr = n())
standard_dev_all_840_ad <- standard_dev_all_840_ad %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)
standard_dev_all_840_ad %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1986 6.729334
1987 7.211134
1988 7.975188
1989 7.874323
1990 7.334504
1991 7.648553
1992 6.993487
1995 6.945265
1996 7.326356
1997 7.346542
1998 7.819710
1999 6.756828
2000 7.298996
2001 7.766886
2002 8.021992
2003 7.460019
2004 7.506468
2007 7.729865
2008 7.977294
2009 7.094470
2010 8.099982
2011 7.955897
2012 7.804828
2014 7.585948
2015 6.894260
2016 7.700243
2017 7.247788
2018 7.180489
2019 7.751133
2020 7.887037
2021 7.885810
2022 7.530352
ggplot(standard_dev_all_840_ad, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Morrisey-corrected standard deviation of SNOTEL 840 average temperatures for water years 1986-2021

MK & SS 840 (corrected)

sd_mk_840_ad <- mk.test(standard_dev_all_840_ad$sd_2)
print(sd_mk_840_ad)
## 
##  Mann-Kendall trend test
## 
## data:  standard_dev_all_840_ad$sd_2
## z = 1.2811, n = 32, p-value = 0.2002
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##            S         varS          tau 
##   80.0000000 3802.6666667    0.1612903
sd_sens_840_ad <- sens.slope(standard_dev_all_840_ad$sd_2)
print(sd_sens_840_ad)
## 
##  Sen's slope
## 
## data:  standard_dev_all_840_ad$sd_2
## z = 1.2811, n = 32, p-value = 0.2002
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.005553565  0.027024754
## sample estimates:
## Sen's slope 
##   0.0120862

Summer and Winter SD NOT-CORRECTED

Summer

summer_standard_dev_all_840 <- standard_dev_840 %>%
  filter(waterDay >= 244 & waterDay <= 335) %>%
  group_by(waterYear) %>% 
  mutate(nmbr = n())

summer_standard_dev_all_840 <- summer_standard_dev_all_840 %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)

summer_standard_dev_all_840 %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1986 2.274917
1987 2.014396
1988 2.306036
1989 2.601399
1990 2.247671
1991 2.398805
1992 2.430312
1995 3.100283
1996 1.667998
1997 2.117495
1998 2.789071
1999 2.553329
2000 1.581360
2001 2.145173
2002 1.886740
2003 3.709504
2004 1.898981
2007 2.169470
2008 2.201448
2009 2.474110
2010 1.975030
2011 1.916261
2012 1.403117
2014 1.738023
2015 1.863685
2016 2.211199
2017 1.720494
2018 1.737876
2019 2.178636
2020 1.812582
2021 1.913112
2022 1.866278
ggplot(summer_standard_dev_all_840, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Non-corrected standard deviation of SNOTEL 840 average summer temperatures for water years 2005-2021

summer MK & SS for 840 (non-corrected)

summer_sd_mk_840 <- mk.test(summer_standard_dev_all_840$sd_2)
print(summer_sd_mk_840)
## 
##  Mann-Kendall trend test
## 
## data:  summer_standard_dev_all_840$sd_2
## z = -2.546, n = 32, p-value = 0.0109
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##            S         varS          tau 
## -158.0000000 3802.6666667   -0.3185484
summer_sd_sens_840 <- sens.slope(summer_standard_dev_all_840$sd_2)
print(summer_sd_sens_840)
## 
##  Sen's slope
## 
## data:  summer_standard_dev_all_840$sd_2
## z = -2.546, n = 32, p-value = 0.0109
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.030042231 -0.004937269
## sample estimates:
## Sen's slope 
## -0.01778031

Winter

winter_standard_dev_all_840 <- standard_dev_840 %>%
  filter(waterDay >= 32 & waterDay <= 182) %>%
  group_by(waterYear) %>% 
  mutate(nmbr = n())

winter_standard_dev_all_840 <- winter_standard_dev_all_840 %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)

winter_standard_dev_all_840 %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1986 4.774693
1987 3.822681
1988 4.648221
1989 5.389172
1990 4.690399
1991 4.527467
1992 3.655616
1995 4.088895
1996 4.445300
1997 4.471830
1998 4.047841
1999 4.028955
2000 4.447934
2001 3.687388
2002 4.814735
2003 3.749425
2004 5.060374
2007 4.823105
2008 5.320894
2009 4.166805
2010 4.213437
2011 4.840786
2012 3.843512
2014 3.850854
2015 4.398650
2016 4.360824
2017 4.818284
2018 3.997183
2019 3.686866
2020 4.015668
2021 4.025477
2022 4.164016
ggplot(winter_standard_dev_all_840, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Non-corrected standard deviation of SNOTEL 840 average winter temperatures for water years 2005-2021

winter MK & SS for 840 (non-corrected)

winter_sd_mk_840 <- mk.test(winter_standard_dev_all_840$sd_2)
print(winter_sd_mk_840)
## 
##  Mann-Kendall trend test
## 
## data:  winter_standard_dev_all_840$sd_2
## z = -1.1838, n = 32, p-value = 0.2365
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##            S         varS          tau 
##  -74.0000000 3802.6666667   -0.1491935
winter_sd_sens_840 <- sens.slope(winter_standard_dev_all_840$sd_2)
print(winter_sd_sens_840)
## 
##  Sen's slope
## 
## data:  winter_standard_dev_all_840$sd_2
## z = -1.1838, n = 32, p-value = 0.2365
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.029810141  0.008846282
## sample estimates:
## Sen's slope 
##  -0.0142895

Summer and Winter SD CORRECTED

Summer

summer_standard_dev_all_840_ad <- standard_dev_840_ad %>% 
  filter(waterDay >= 244 & waterDay <= 335) %>%
  group_by(waterYear) %>% 
  mutate(nmbr = n())
summer_standard_dev_all_840_ad <- summer_standard_dev_all_840_ad %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)
summer_standard_dev_all_840_ad %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1986 2.048138
1987 1.805643
1988 2.080518
1989 2.332076
1990 2.018498
1991 2.161691
1992 2.189199
1995 2.788317
1996 1.495646
1997 1.905083
1998 2.507667
1999 2.300968
2000 1.413289
2001 1.928350
2002 1.687157
2003 3.345166
2004 1.896649
2007 2.165544
2008 2.195558
2009 2.468649
2010 1.973357
2011 1.910791
2012 1.400205
2014 1.732726
2015 1.861873
2016 2.207700
2017 1.714988
2018 1.734873
2019 2.175222
2020 1.808042
2021 1.908372
2022 1.866056
ggplot(summer_standard_dev_all_840_ad, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Morrisey-corrected standard deviation of SNOTEL 840 average summer temperatures for water years 1986-2021

summer MK & SS 840 (corrected)

summer_sd_mk_840_ad <- mk.test(summer_standard_dev_all_840_ad$sd_2)
print(summer_sd_mk_840_ad)
## 
##  Mann-Kendall trend test
## 
## data:  summer_standard_dev_all_840_ad$sd_2
## z = -1.3135, n = 32, p-value = 0.189
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##            S         varS          tau 
##  -82.0000000 3802.6666667   -0.1653226
summer_sd_sens_840_ad <- sens.slope(summer_standard_dev_all_840_ad$sd_2)
print(summer_sd_sens_840_ad)
## 
##  Sen's slope
## 
## data:  summer_standard_dev_all_840_ad$sd_2
## z = -1.3135, n = 32, p-value = 0.189
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.019782521  0.003642474
## sample estimates:
##  Sen's slope 
## -0.007464632

Winter

winter_standard_dev_all_840_ad <- standard_dev_840_ad %>% 
  filter(waterDay >= 32 & waterDay <= 182) %>%
  group_by(waterYear) %>% 
  mutate(nmbr = n())
winter_standard_dev_all_840_ad <- winter_standard_dev_all_840_ad %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)
winter_standard_dev_all_840_ad %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1986 4.554830
1987 3.694189
1988 4.518723
1989 5.236614
1990 4.529536
1991 4.434653
1992 3.543302
1995 3.950999
1996 4.306141
1997 4.322590
1998 3.908977
1999 3.880739
2000 4.275877
2001 3.576831
2002 4.625719
2003 3.625912
2004 4.900833
2007 4.822356
2008 5.320773
2009 4.166644
2010 4.213133
2011 4.841004
2012 3.843578
2014 3.851521
2015 4.398320
2016 4.361393
2017 4.817629
2018 3.996842
2019 3.687656
2020 4.015777
2021 4.025580
2022 4.164509
ggplot(winter_standard_dev_all_840_ad, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Morrisey-corrected standard deviation of SNOTEL 840 average winter temperatures for water years 1986-2021

winter MK & SS 840 (corrected)

winter_sd_mk_840_ad <- mk.test(winter_standard_dev_all_840_ad$sd_2)
print(winter_sd_mk_840_ad)
## 
##  Mann-Kendall trend test
## 
## data:  winter_standard_dev_all_840_ad$sd_2
## z = -0.63244, n = 32, p-value = 0.5271
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##             S          varS           tau 
##  -40.00000000 3802.66666667   -0.08064516
winter_sd_sens_840_ad <- sens.slope(winter_standard_dev_all_840_ad$sd_2)
print(winter_sd_sens_840_ad)
## 
##  Sen's slope
## 
## data:  winter_standard_dev_all_840_ad$sd_2
## z = -0.63244, n = 32, p-value = 0.5271
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.02273985  0.01362733
## sample estimates:
##  Sen's slope 
## -0.007000917

Spring and Fall SD NOT-CORRECTED

Spring

spring_standard_dev_all_840 <- standard_dev_840 %>%
  filter(waterDay >= 183 & waterDay <= 243) %>%
  group_by(waterYear) %>% 
  mutate(nmbr = n())

spring_standard_dev_all_840 <- spring_standard_dev_all_840 %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)

spring_standard_dev_all_840 %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1986 3.589968
1987 2.997633
1988 3.967163
1989 3.557639
1990 2.601120
1991 4.427092
1992 2.644233
1995 3.416205
1996 4.617813
1997 4.614675
1998 4.460178
1999 4.744377
2000 4.023575
2001 4.224318
2002 3.262379
2003 4.473951
2004 3.322026
2007 3.266946
2008 3.760980
2009 4.203341
2010 4.269914
2011 3.824194
2012 3.592784
2014 4.274434
2015 2.566465
2016 3.309034
2017 3.871109
2018 3.509557
2019 3.009469
2020 3.692800
2021 3.150615
2022 3.945521
ggplot(spring_standard_dev_all_840, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Non-corrected standard deviation of SNOTEL 840 average spring temperatures for water years 2005-2021

spring MK & SS for 840 (non-corrected)

spring_sd_mk_840 <- mk.test(spring_standard_dev_all_840$sd_2)
print(spring_sd_mk_840)
## 
##  Mann-Kendall trend test
## 
## data:  spring_standard_dev_all_840$sd_2
## z = -0.66487, n = 32, p-value = 0.5061
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##             S          varS           tau 
##  -42.00000000 3802.66666667   -0.08467742
spring_sd_sens_840 <- sens.slope(spring_standard_dev_all_840$sd_2)
print(spring_sd_sens_840)
## 
##  Sen's slope
## 
## data:  spring_standard_dev_all_840$sd_2
## z = -0.66487, n = 32, p-value = 0.5061
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.03683439  0.01701452
## sample estimates:
## Sen's slope 
## -0.01106388

Fall

Fall is split each water year in the middle of the season. This analysis splits the fall season between the preceding water year and the subsequent water year.

fall_standard_dev_all_840 <- standard_dev_840 %>%
  filter(waterDay >= 336 | waterDay <= 31) %>% 
  group_by(waterYear) %>% 
  mutate(nmbr = n())

fall_standard_dev_all_840 <- fall_standard_dev_all_840 %>% 
  #group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)

fall_standard_dev_all_840 %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1986 2.871951
1987 3.371115
1988 3.166251
1989 2.814779
1990 4.815384
1991 3.360282
1992 4.148522
1995 4.670215
1996 3.719224
1997 5.713225
1998 5.237184
1999 3.195878
2000 3.694949
2001 3.936887
2002 3.293871
2003 4.059913
2004 2.998505
2007 4.227635
2008 2.845129
2009 3.277436
2010 5.205363
2011 3.596520
2012 4.150658
2014 4.876923
2015 2.842277
2016 3.095013
2017 3.086942
2018 3.406979
2019 4.150925
2020 5.585502
2021 3.841002
2022 4.654778
ggplot(fall_standard_dev_all_840, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Non-corrected standard deviation of SNOTEL 840 average fall temperatures for water years 2005-2021. Note that the season is split by the water year.

fall MK & SS for 840 (non-corrected)

fall_sd_mk_840 <- mk.test(fall_standard_dev_all_840$sd_2)
print(fall_sd_mk_840)
## 
##  Mann-Kendall trend test
## 
## data:  fall_standard_dev_all_840$sd_2
## z = 0.82704, n = 32, p-value = 0.4082
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##            S         varS          tau 
##   52.0000000 3802.6666667    0.1048387
fall_sd_sens_840 <- sens.slope(fall_standard_dev_all_840$sd_2)
print(fall_sd_sens_840)
## 
##  Sen's slope
## 
## data:  fall_standard_dev_all_840$sd_2
## z = 0.82704, n = 32, p-value = 0.4082
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.01724415  0.04866987
## sample estimates:
## Sen's slope 
##  0.01282857

Spring and Fall SD CORRECTED

Spring

spring_standard_dev_all_840_ad <- standard_dev_840_ad %>% 
  filter(waterDay >= 183 & waterDay <= 243) %>%
  group_by(waterYear) %>% 
  mutate(nmbr = n())
spring_standard_dev_all_840_ad <- spring_standard_dev_all_840_ad %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)
spring_standard_dev_all_840_ad %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1986 3.315418
1987 2.771291
1988 3.666824
1989 3.256690
1990 2.388223
1991 4.126689
1992 2.428817
1995 3.176479
1996 4.248156
1997 4.313361
1998 4.141484
1999 4.432340
2000 3.687881
2001 3.899794
2002 2.975207
2003 4.134036
2004 3.297293
2007 3.265156
2008 3.758951
2009 4.200068
2010 4.268056
2011 3.822200
2012 3.591304
2014 4.272145
2015 2.564843
2016 3.307421
2017 3.868032
2018 3.507820
2019 3.007769
2020 3.690197
2021 3.149182
2022 3.942685
ggplot(spring_standard_dev_all_840_ad, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Morrisey-corrected standard deviation of SNOTEL 840 average spring temperatures for water years 1986-2021

spring MK & SS 840 (corrected)

spring_sd_mk_840_ad <- mk.test(spring_standard_dev_all_840_ad$sd_2)
print(spring_sd_mk_840_ad)
## 
##  Mann-Kendall trend test
## 
## data:  spring_standard_dev_all_840_ad$sd_2
## z = 0.47028, n = 32, p-value = 0.6382
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##            S         varS          tau 
## 3.000000e+01 3.802667e+03 6.048387e-02
spring_sd_sens_840_ad <- sens.slope(spring_standard_dev_all_840_ad$sd_2)
print(spring_sd_sens_840_ad)
## 
##  Sen's slope
## 
## data:  spring_standard_dev_all_840_ad$sd_2
## z = 0.47028, n = 32, p-value = 0.6382
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.02144856  0.03020133
## sample estimates:
## Sen's slope 
## 0.005262267

Fall

fall_standard_dev_all_840_ad <- standard_dev_840_ad %>% 
  filter(waterDay >= 336 | waterDay <= 31) %>%
  group_by(waterYear) %>% 
  mutate(nmbr = n())
fall_standard_dev_all_840_ad <- fall_standard_dev_all_840_ad %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)
fall_standard_dev_all_840_ad %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1986 2.626139
1987 3.098930
1988 2.877504
1989 2.554880
1990 4.422413
1991 3.084872
1992 3.853735
1995 4.276837
1996 3.403621
1997 5.279914
1998 4.824393
1999 2.933334
2000 3.364255
2001 3.604148
2002 2.998427
2003 3.726059
2004 2.687604
2007 4.228226
2008 2.845719
2009 3.278955
2010 5.207930
2011 3.597545
2012 4.151020
2014 4.876169
2015 2.844492
2016 3.095142
2017 3.086326
2018 3.407980
2019 4.152594
2020 5.585839
2021 3.840160
2022 4.655201
ggplot(fall_standard_dev_all_840_ad, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Morrisey-corrected standard deviation of SNOTEL 840 average fall temperatures for water years 1986-2021. Note that the fall season is split by the water year.

fall MK & SS 840 (corrected)

fall_sd_mk_840_ad <- mk.test(fall_standard_dev_all_840_ad$sd_2)
print(fall_sd_mk_840_ad)
## 
##  Mann-Kendall trend test
## 
## data:  fall_standard_dev_all_840_ad$sd_2
## z = 1.6703, n = 32, p-value = 0.09486
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##            S         varS          tau 
##  104.0000000 3802.6666667    0.2096774
fall_sd_sens_840_ad <- sens.slope(fall_standard_dev_all_840_ad$sd_2)
print(fall_sd_sens_840_ad)
## 
##  Sen's slope
## 
## data:  fall_standard_dev_all_840_ad$sd_2
## z = 1.6703, n = 32, p-value = 0.09486
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.004861105  0.060955378
## sample estimates:
## Sen's slope 
##  0.02931124

Vallecito 843

Morrisey 7/22/2005

snotel_843 <- SNOTEL_san_juan_Area %>% 
  filter(site_id == "843")
#str(snotel_843) # check the date, usually a character.  

snotel_843$Date <- as.Date(snotel_843$date) #change date from character to date format, capitalize to work with Water year functon from NWIS.

#THIS WILL CHANGE FOR EACH STATION
snotel_843_clean <- snotel_843 %>% # filter for the timeframe
  filter(Date >= "1979-10-01" & Date <= "2022-09-30") %>%
  #filter(temperature_mean >= -30 & temperature_mean <= 20) %>% # removing outliers   
  addWaterYear() %>% 
  mutate(daymonth = format(as.Date(Date), "%d-%m")) %>% 
  na.omit()

#adding water day using difftime (SUPER COOL. example from [this](https://stackoverflow.com/questions/48123049/create-day-index-based-on-water-year))

snotel_843_clean <- snotel_843_clean %>% 
  group_by(waterYear)%>% 
  mutate(waterDay = (as.integer(difftime(Date, ymd(paste0(waterYear - 1 ,'-09-30')), units = "days"))))
# Check for outliers

ggplot(snotel_843_clean, aes(x = Date, y = temperature_mean)) +
  geom_point() + #lwd = 2) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('Daily temperature (°C)') + 
  xlab('Date')

snotel_843_clean <- snotel_843_clean %>% 
  mutate(temp_diff = abs(temperature_min - temperature_max)) %>% 
  filter(temperature_mean > -40) %>% 
  filter(temperature_mean < 25)
ggplot(snotel_843_clean, aes(x = Date, y = temp_diff)) + 
  geom_point() + #lwd = 2) +
  theme_few() +
  #geom_smooth(method = "lm", se=FALSE) +
  ylab('Daily temperature varience (°C)') + 
  xlab('Date')

Per Steven’s advice: :If there are more than 15 missing days, then…remove that year”

# filtering for temperature anomalies
#snotel_843_cull_count <- snotel_843_clean %>% 
#  filter(temperature_min > -40) %>% 
#  count(waterYear)

#snotel_843_cull_count

# filtering for too few observations in a year
snotel_843_cull_count_days <- snotel_843_clean %>% 
  group_by(waterYear) %>% 
  count(waterYear) %>% 
  filter(n < 350)

snotel_843_cull_count_days
## # A tibble: 2 x 2
## # Groups:   waterYear [2]
##   waterYear     n
##       <dbl> <int>
## 1      1994   339
## 2      2003   313

1994 & 2003 need to be culled.

snotel_843_clean_culled <- snotel_843_clean %>% 
  filter(waterYear != "1994" & waterYear != "2003")# & waterYear != "1994" & waterYear != "2005" & waterYear != "2006" & waterYear != "2013")# & waterYear != "2022") & waterYear != "2014") #%>% 
  #filter(temperature_mean > -49)

ggplot(snotel_843_clean_culled, aes(x = Date, y = temp_diff)) + 
  geom_point() + #lwd = 2) +
  theme_few() +
  #geom_smooth(method = "lm", se=FALSE) +
  ylab('Daily temperature varience (°C)') + 
  xlab('Date')

ggplot(snotel_843_clean_culled, aes(x = Date, y = temperature_mean)) + 
  geom_point() + #lwd = 2) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('Daily temperature (°C)') + 
  xlab('Date')

temp_843_xts <- xts(snotel_843_clean_culled$temperature_mean, order.by = snotel_843_clean_culled$Date)

dygraph(temp_843_xts) %>%
  dyAxis("y", label = "Daily mean temperature (°C)") 
#snotel_843_clean_culled <- snotel_843_clean_culled %>% 
#  filter(temperature_mean < 19.3)

temp_843_xts <- xts(snotel_843_clean_culled$temperature_mean, order.by = snotel_843_clean_culled$Date)

dygraph(temp_843_xts) %>%
  dyAxis("y", label = "Daily mean temperature (°C)") 

Vallecito 843

Morrisey 7/22/2005

snotel_843_adjusted <- snotel_843_clean_culled %>%
  mutate(temp_ad = if_else(Date < "2005-07-22", ((5.3*10^(-7))*(temperature_mean^(4))+(3.72*10^(-5))*(temperature_mean^(3))-(2.16*10^(-3))*(temperature_mean^(2))-(7.32*10^(-2))*(temperature_mean)+1.37)+temperature_mean, temperature_mean))

Non-corrected

843 Detrended

#using the clean culled df:

#average water year temperature

yearly_wy_aver_843 <- snotel_843_adjusted %>% 
  group_by(waterYear) %>% 
  mutate(aver_ann_temp = mean(temperature_mean))

#Average temperature by day for all water years:

daily_wy_aver_843 <- yearly_wy_aver_843 %>% 
  group_by(daymonth) %>% 
  mutate(aver_day_temp = mean(aver_ann_temp))

#average mean temperature by day for the period of record:

daily_wy_aver_843 <- daily_wy_aver_843 %>% 
  group_by(daymonth) %>% 
  mutate(all_ave_temp = mean(daily_wy_aver_843$aver_day_temp))

# try to show all years as means. 
daily_wy_aver2_843 <-daily_wy_aver_843 %>% 
  group_by(waterDay) %>%
  mutate(date_temp = mean(temperature_mean))
  

daily_wy_aver2_843$date_temp <- signif(daily_wy_aver2_843$date_temp,3) #reduce the sig figs


ggplot(daily_wy_aver2_843, aes(x = waterDay, y = date_temp))+
  geom_line(size= 0.7) +
  theme_few() +
  ylab('Average Daily temperature (°C)') + 
  xlab('Day of water year')

843 SD

standard_dev_843 <- daily_wy_aver_843 %>% 
  group_by(waterYear) %>% 
  mutate(residual = (all_ave_temp-aver_ann_temp)+temperature_mean-aver_day_temp) %>% 
  mutate(deviation = abs(residual-lag(residual)))

standard_dev_all_843 <- standard_dev_843 %>% 
  group_by(waterYear) %>% 
  mutate(nmbr = n())

standard_dev_all_843 <- standard_dev_all_843 %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)

standard_dev_all_843 %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1987 7.744307
1988 8.133975
1989 8.353802
1990 7.814664
1991 7.913458
1992 7.258470
1993 8.017543
1995 7.737939
1996 8.012757
1997 8.122829
1998 8.284299
1999 6.874497
2000 8.036954
2001 8.326535
2002 8.475624
2004 5.169906
2005 7.879202
2006 7.087987
2007 7.572592
2008 8.035842
2009 7.216959
2010 7.825626
2011 7.886538
2012 7.648815
2013 8.040098
2014 7.292347
2015 6.734206
2016 7.523001
2017 7.419976
2018 7.106676
2019 7.826098
2020 7.899858
2021 7.970432
2022 7.307690
ggplot(standard_dev_all_843, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Non-corrected standard deviation of SNOTEL 843 average temperatures for water years 2005-2021

MK & SS for 843 (non-corrected)

sd_mk_843 <- mk.test(standard_dev_all_843$sd_2)
print(sd_mk_843)
## 
##  Mann-Kendall trend test
## 
## data:  standard_dev_all_843$sd_2
## z = -1.6307, n = 34, p-value = 0.103
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##           S        varS         tau 
## -111.000000 4550.333333   -0.197861
sd_sens_843 <- sens.slope(standard_dev_all_843$sd_2)
print(sd_sens_843)
## 
##  Sen's slope
## 
## data:  standard_dev_all_843$sd_2
## z = -1.6307, n = 34, p-value = 0.103
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.029639051  0.001693822
## sample estimates:
## Sen's slope 
## -0.01383409

Corrected

843 Detrended (corrected)

#using the clean culled df:
#average water year temperature
yearly_wy_aver_843_ad <- snotel_843_adjusted %>% 
  group_by(waterYear) %>% 
  mutate(aver_ann_temp_ad = mean(temp_ad))
#Average temperature by day for all water years:
daily_wy_aver_843_ad <- yearly_wy_aver_843_ad %>% 
  group_by(daymonth) %>% 
  mutate(aver_day_temp_ad = mean(aver_ann_temp_ad))
#average mean temperature by day for the period of record:
daily_wy_aver_843_ad <- daily_wy_aver_843_ad %>% 
  group_by(daymonth) %>% 
  mutate(all_ave_temp_ad = mean(daily_wy_aver_843_ad$aver_day_temp_ad))
# try to show all years as means. 
daily_wy_aver2_843_ad <-daily_wy_aver_843_ad %>% 
  group_by(waterDay) %>%
  mutate(date_temp_ad = mean(temp_ad))
  
daily_wy_aver2_843_ad$date_temp_ad <- signif(daily_wy_aver2_843_ad$date_temp_ad,3) #reduce the sig figs
ggplot(daily_wy_aver2_843_ad, aes(x = waterDay, y = date_temp_ad))+
  geom_line(size= 0.7) +
  theme_few() +
  ylab('Average Daily temperature (°C)') + 
  xlab('Day of water year')

843 SS (corrected)

standard_dev_843_ad <- daily_wy_aver_843_ad %>% 
  group_by(waterYear) %>% 
  #filter(waterYear >= 1987 & waterYear <= 2021) %>% 
  mutate(residual = (all_ave_temp_ad-aver_ann_temp_ad)+temp_ad-aver_day_temp_ad) %>% 
  mutate(deviation = abs(residual-lag(residual)))
standard_dev_all_843_ad <- standard_dev_843_ad %>% 
  group_by(waterYear) %>% 
  mutate(nmbr = n())
standard_dev_all_843_ad <- standard_dev_all_843_ad %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)
standard_dev_all_843_ad %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1987 7.167709
1988 7.554905
1989 7.775142
1990 7.236968
1991 7.363376
1992 6.713681
1993 7.440691
1995 7.144630
1996 7.409097
1997 7.529924
1998 7.661187
1999 6.355448
2000 7.405969
2001 7.695693
2002 7.828232
2004 4.700776
2005 7.205286
2006 7.087285
2007 7.571307
2008 8.034938
2009 7.215649
2010 7.824301
2011 7.885342
2012 7.647841
2013 8.038906
2014 7.290741
2015 6.733530
2016 7.521405
2017 7.418681
2018 7.106001
2019 7.824924
2020 7.898803
2021 7.969378
2022 7.306728
ggplot(standard_dev_all_843_ad, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Morrisey-corrected standard deviation of SNOTEL 843 average temperatures for water years 1986-2021

MK & SS 843 (corrected)

sd_mk_843_ad <- mk.test(standard_dev_all_843_ad$sd_2)
print(sd_mk_843_ad)
## 
##  Mann-Kendall trend test
## 
## data:  standard_dev_all_843_ad$sd_2
## z = 1.601, n = 34, p-value = 0.1094
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##            S         varS          tau 
##  109.0000000 4550.3333333    0.1942959
sd_sens_843_ad <- sens.slope(standard_dev_all_843_ad$sd_2)
print(sd_sens_843_ad)
## 
##  Sen's slope
## 
## data:  standard_dev_all_843_ad$sd_2
## z = 1.601, n = 34, p-value = 0.1094
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.003122605  0.025938612
## sample estimates:
## Sen's slope 
##  0.01173229

Summer and Winter SD NOT-CORRECTED

Summer

summer_standard_dev_all_843 <- standard_dev_843 %>%
  filter(waterDay >= 244 & waterDay <= 335) %>%
  group_by(waterYear) %>% 
  mutate(nmbr = n())

summer_standard_dev_all_843 <- summer_standard_dev_all_843 %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)

summer_standard_dev_all_843 %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1987 2.346128
1988 2.619944
1989 3.207520
1990 3.072873
1991 2.786863
1992 3.068047
1993 3.467390
1995 3.677577
1996 2.664453
1997 2.702126
1998 3.450109
1999 2.792686
2000 2.168160
2001 2.542518
2002 2.375215
2004 2.630202
2005 3.243469
2006 1.930584
2007 2.542558
2008 2.498186
2009 3.197280
2010 2.771228
2011 2.011123
2012 1.723698
2013 1.947043
2014 2.148983
2015 2.426192
2016 2.517098
2017 2.064627
2018 2.085587
2019 2.503624
2020 2.565695
2021 2.289562
2022 2.412832
ggplot(summer_standard_dev_all_843, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Non-corrected standard deviation of SNOTEL 843 average summer temperatures for water years 2005-2021

summer MK & SS for 843 (non-corrected)

summer_sd_mk_843 <- mk.test(summer_standard_dev_all_843$sd_2)
print(summer_sd_mk_843)
## 
##  Mann-Kendall trend test
## 
## data:  summer_standard_dev_all_843$sd_2
## z = -2.9945, n = 34, p-value = 0.002749
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##            S         varS          tau 
## -203.0000000 4550.3333333   -0.3618538
summer_sd_sens_843 <- sens.slope(summer_standard_dev_all_843$sd_2)
print(summer_sd_sens_843)
## 
##  Sen's slope
## 
## data:  summer_standard_dev_all_843$sd_2
## z = -2.9945, n = 34, p-value = 0.002749
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.041071297 -0.008191406
## sample estimates:
## Sen's slope 
## -0.02257691

Winter

winter_standard_dev_all_843 <- standard_dev_843 %>%
  filter(waterDay >= 32 & waterDay <= 182) %>%
  group_by(waterYear) %>% 
  mutate(nmbr = n())

winter_standard_dev_all_843 <- winter_standard_dev_all_843 %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)

winter_standard_dev_all_843 %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1987 4.427912
1988 5.012550
1989 5.858939
1990 5.137108
1991 5.098992
1992 3.783912
1993 4.392078
1995 4.409859
1996 5.219231
1997 5.177420
1998 4.241123
1999 4.162789
2000 5.025710
2001 4.113427
2002 4.994185
2004 3.396785
2005 4.269988
2006 4.436911
2007 5.083808
2008 5.399585
2009 4.738283
2010 4.413961
2011 5.042425
2012 4.274299
2013 5.604427
2014 4.189625
2015 4.527692
2016 4.757855
2017 5.048261
2018 4.236822
2019 3.981781
2020 4.218900
2021 4.453029
2022 4.873308
ggplot(winter_standard_dev_all_843, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Non-corrected standard deviation of SNOTEL 843 average winter temperatures for water years 2005-2021

winter MK & SS for 843 (non-corrected)

winter_sd_mk_843 <- mk.test(winter_standard_dev_all_843$sd_2)
print(winter_sd_mk_843)
## 
##  Mann-Kendall trend test
## 
## data:  winter_standard_dev_all_843$sd_2
## z = -0.91912, n = 34, p-value = 0.358
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##            S         varS          tau 
##  -63.0000000 4550.3333333   -0.1122995
winter_sd_sens_843 <- sens.slope(winter_standard_dev_all_843$sd_2)
print(winter_sd_sens_843)
## 
##  Sen's slope
## 
## data:  winter_standard_dev_all_843$sd_2
## z = -0.91912, n = 34, p-value = 0.358
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.030910729  0.009292454
## sample estimates:
##  Sen's slope 
## -0.007865349

Summer and Winter SD CORRECTED

Summer

summer_standard_dev_all_843_ad <- standard_dev_843_ad %>% 
  filter(waterDay >= 244 & waterDay <= 335) %>%
  group_by(waterYear) %>% 
  mutate(nmbr = n())
summer_standard_dev_all_843_ad <- summer_standard_dev_all_843_ad %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)
summer_standard_dev_all_843_ad %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1987 2.105328
1988 2.357017
1989 2.872795
1990 2.756770
1991 2.511435
1992 2.759558
1993 3.123166
1995 3.304335
1996 2.386285
1997 2.428904
1998 3.100500
1999 2.519729
2000 1.940468
2001 2.284102
2002 2.126206
2004 2.355973
2005 2.945878
2006 1.930028
2007 2.542672
2008 2.499493
2009 3.195425
2010 2.767912
2011 2.010535
2012 1.723562
2013 1.947511
2014 2.148154
2015 2.427029
2016 2.515887
2017 2.063971
2018 2.086096
2019 2.502777
2020 2.565655
2021 2.289051
2022 2.411675
ggplot(summer_standard_dev_all_843_ad, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Morrisey-corrected standard deviation of SNOTEL 843 average summer temperatures for water years 1986-2021

summer MK & SS 843 (corrected)

summer_sd_mk_843_ad <- mk.test(summer_standard_dev_all_843_ad$sd_2)
print(summer_sd_mk_843_ad)
## 
##  Mann-Kendall trend test
## 
## data:  summer_standard_dev_all_843_ad$sd_2
## z = -1.3935, n = 34, p-value = 0.1635
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##            S         varS          tau 
##  -95.0000000 4550.3333333   -0.1693405
summer_sd_sens_843_ad <- sens.slope(summer_standard_dev_all_843_ad$sd_2)
print(summer_sd_sens_843_ad)
## 
##  Sen's slope
## 
## data:  summer_standard_dev_all_843_ad$sd_2
## z = -1.3935, n = 34, p-value = 0.1635
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.027423400  0.002497495
## sample estimates:
## Sen's slope 
## -0.01107592

Winter

winter_standard_dev_all_843_ad <- standard_dev_843_ad %>% 
  filter(waterDay >= 32 & waterDay <= 182) %>%
  group_by(waterYear) %>% 
  mutate(nmbr = n())
winter_standard_dev_all_843_ad <- winter_standard_dev_all_843_ad %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)
winter_standard_dev_all_843_ad %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1987 4.224648
1988 4.806735
1989 5.639223
1990 4.895536
1991 4.901330
1992 3.611549
1993 4.226666
1995 4.200474
1996 4.980076
1997 4.922782
1998 4.043928
1999 3.958859
2000 4.747752
2001 3.935747
2002 4.753771
2004 3.128328
2005 4.061855
2006 4.436952
2007 5.082876
2008 5.398178
2009 4.737126
2010 4.413584
2011 5.040957
2012 4.274462
2013 5.603638
2014 4.188733
2015 4.527289
2016 4.756252
2017 5.047793
2018 4.236955
2019 3.981614
2020 4.218761
2021 4.452850
2022 4.872764
ggplot(winter_standard_dev_all_843_ad, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Morrisey-corrected standard deviation of SNOTEL 843 average winter temperatures for water years 1986-2021

winter MK & SS 843 (corrected)

winter_sd_mk_843_ad <- mk.test(winter_standard_dev_all_843_ad$sd_2)
print(winter_sd_mk_843_ad)
## 
##  Mann-Kendall trend test
## 
## data:  winter_standard_dev_all_843_ad$sd_2
## z = 0.059298, n = 34, p-value = 0.9527
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##            S         varS          tau 
## 5.000000e+00 4.550333e+03 8.912656e-03
winter_sd_sens_843_ad <- sens.slope(winter_standard_dev_all_843_ad$sd_2)
print(winter_sd_sens_843_ad)
## 
##  Sen's slope
## 
## data:  winter_standard_dev_all_843_ad$sd_2
## z = 0.059298, n = 34, p-value = 0.9527
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.02034928  0.01882551
## sample estimates:
##  Sen's slope 
## 0.0004243853

Spring and Fall SD NOT-CORRECTED

Spring

spring_standard_dev_all_843 <- standard_dev_843 %>%
  filter(waterDay >= 183 & waterDay <= 243) %>%
  group_by(waterYear) %>% 
  mutate(nmbr = n())

spring_standard_dev_all_843 <- spring_standard_dev_all_843 %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)

spring_standard_dev_all_843 %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1987 3.396561
1988 5.064959
1989 4.261071
1990 3.313330
1991 4.904835
1992 3.274761
1993 4.529354
1995 3.897692
1996 5.048053
1997 5.615558
1998 5.200676
1999 5.235320
2000 4.981248
2001 5.428363
2002 4.040845
2004 3.027690
2005 4.845333
2006 4.034505
2007 4.234866
2008 4.351772
2009 4.884579
2010 4.632008
2011 4.117048
2012 4.073015
2013 4.276573
2014 4.799770
2015 3.285381
2016 3.797315
2017 4.149242
2018 4.127623
2019 3.502806
2020 4.280603
2021 3.745055
2022 4.341386
ggplot(spring_standard_dev_all_843, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Non-corrected standard deviation of SNOTEL 843 average spring temperatures for water years 2005-2021

spring MK & SS for 843 (non-corrected)

spring_sd_mk_843 <- mk.test(spring_standard_dev_all_843$sd_2)
print(spring_sd_mk_843)
## 
##  Mann-Kendall trend test
## 
## data:  spring_standard_dev_all_843$sd_2
## z = -1.2453, n = 34, p-value = 0.213
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##            S         varS          tau 
##  -85.0000000 4550.3333333   -0.1515152
spring_sd_sens_843 <- sens.slope(spring_standard_dev_all_843$sd_2)
print(spring_sd_sens_843)
## 
##  Sen's slope
## 
## data:  spring_standard_dev_all_843$sd_2
## z = -1.2453, n = 34, p-value = 0.213
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.043765947  0.009811527
## sample estimates:
## Sen's slope 
## -0.01835214

Fall

Fall is split each water year in the middle of the season. This analysis splits the fall season between the preceding water year and the subsequent water year.

fall_standard_dev_all_843 <- standard_dev_843 %>%
  filter(waterDay >= 336 | waterDay <= 31) %>% 
  group_by(waterYear) %>% 
  mutate(nmbr = n())

fall_standard_dev_all_843 <- fall_standard_dev_all_843 %>% 
  #group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)

fall_standard_dev_all_843 %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1987 4.049242
1988 3.521288
1989 2.942715
1990 5.393705
1991 3.451184
1992 5.317301
1993 3.677725
1995 5.093885
1996 4.145109
1997 6.140348
1998 5.080139
1999 4.060450
2000 3.892317
2001 5.320073
2002 3.604182
2004 3.596442
2005 5.158267
2006 3.353480
2007 4.539519
2008 3.555504
2009 3.705594
2010 5.945590
2011 4.139390
2012 4.741882
2013 4.006560
2014 5.349983
2015 3.299325
2016 3.706150
2017 3.547324
2018 3.512034
2019 4.895098
2020 6.104717
2021 4.364059
2022 5.153786
ggplot(fall_standard_dev_all_843, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Non-corrected standard deviation of SNOTEL 843 average fall temperatures for water years 2005-2021. Note that the season is split by the water year.

fall MK & SS for 843 (non-corrected)

fall_sd_mk_843 <- mk.test(fall_standard_dev_all_843$sd_2)
print(fall_sd_mk_843)
## 
##  Mann-Kendall trend test
## 
## data:  fall_standard_dev_all_843$sd_2
## z = 0.32614, n = 34, p-value = 0.7443
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##            S         varS          tau 
## 2.300000e+01 4.550333e+03 4.099822e-02
fall_sd_sens_843 <- sens.slope(fall_standard_dev_all_843$sd_2)
print(fall_sd_sens_843)
## 
##  Sen's slope
## 
## data:  fall_standard_dev_all_843$sd_2
## z = 0.32614, n = 34, p-value = 0.7443
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.02334043  0.04023780
## sample estimates:
## Sen's slope 
## 0.003202049

Spring and Fall SD CORRECTED

Spring

spring_standard_dev_all_843_ad <- standard_dev_843_ad %>% 
  filter(waterDay >= 183 & waterDay <= 243) %>%
  group_by(waterYear) %>% 
  mutate(nmbr = n())
spring_standard_dev_all_843_ad <- spring_standard_dev_all_843_ad %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)
spring_standard_dev_all_843_ad %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1987 3.133538
1988 4.674834
1989 3.892914
1990 3.042924
1991 4.571170
1992 2.992912
1993 4.165516
1995 3.628118
1996 4.625312
1997 5.209016
1998 4.824004
1999 4.880077
2000 4.547984
2001 4.997686
2002 3.675921
2004 2.742344
2005 4.435716
2006 4.033887
2007 4.236027
2008 4.352481
2009 4.885190
2010 4.631624
2011 4.117066
2012 4.072965
2013 4.277062
2014 4.798676
2015 3.285370
2016 3.796765
2017 4.148725
2018 4.128789
2019 3.502610
2020 4.280665
2021 3.745541
2022 4.341979
ggplot(spring_standard_dev_all_843_ad, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Morrisey-corrected standard deviation of SNOTEL 843 average spring temperatures for water years 1986-2021

spring MK & SS 843 (corrected)

spring_sd_mk_843_ad <- mk.test(spring_standard_dev_all_843_ad$sd_2)
print(spring_sd_mk_843_ad)
## 
##  Mann-Kendall trend test
## 
## data:  spring_standard_dev_all_843_ad$sd_2
## z = -0.29649, n = 34, p-value = 0.7669
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##             S          varS           tau 
##  -21.00000000 4550.33333333   -0.03743316
spring_sd_sens_843_ad <- sens.slope(spring_standard_dev_all_843_ad$sd_2)
print(spring_sd_sens_843_ad)
## 
##  Sen's slope
## 
## data:  spring_standard_dev_all_843_ad$sd_2
## z = -0.29649, n = 34, p-value = 0.7669
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.02564625  0.02144456
## sample estimates:
##  Sen's slope 
## -0.005456884

Fall

fall_standard_dev_all_843_ad <- standard_dev_843_ad %>% 
  filter(waterDay >= 336 | waterDay <= 31) %>%
  group_by(waterYear) %>% 
  mutate(nmbr = n())
fall_standard_dev_all_843_ad <- fall_standard_dev_all_843_ad %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)
fall_standard_dev_all_843_ad %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1987 3.710766
1988 3.192741
1989 2.663208
1990 4.917326
1991 3.151745
1992 4.931809
1993 3.353595
1995 4.643121
1996 3.780906
1997 5.652541
1998 4.651129
1999 3.713870
2000 3.527909
2001 4.853845
2002 3.270319
2004 3.255990
2005 4.538357
2006 3.354495
2007 4.537330
2008 3.556079
2009 3.705432
2010 5.945309
2011 4.139505
2012 4.740999
2013 4.004427
2014 5.347777
2015 3.300517
2016 3.703186
2017 3.544699
2018 3.512011
2019 4.893876
2020 6.103452
2021 4.361230
2022 5.153590
ggplot(fall_standard_dev_all_843_ad, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Morrisey-corrected standard deviation of SNOTEL 843 average fall temperatures for water years 1986-2021. Note that the fall season is split by the water year.

fall MK & SS 843 (corrected)

fall_sd_mk_843_ad <- mk.test(fall_standard_dev_all_843_ad$sd_2)
print(fall_sd_mk_843_ad)
## 
##  Mann-Kendall trend test
## 
## data:  fall_standard_dev_all_843_ad$sd_2
## z = 1.4824, n = 34, p-value = 0.1382
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##            S         varS          tau 
##  101.0000000 4550.3333333    0.1800357
fall_sd_sens_843_ad <- sens.slope(fall_standard_dev_all_843_ad$sd_2)
print(fall_sd_sens_843_ad)
## 
##  Sen's slope
## 
## data:  fall_standard_dev_all_843_ad$sd_2
## z = 1.4824, n = 34, p-value = 0.1382
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.006348177  0.054907367
## sample estimates:
## Sen's slope 
##  0.02079837

Wolf Creek Summit 874

Morrisey 7/12/2004

snotel_874 <- SNOTEL_san_juan_Area %>% 
  filter(site_id == "874")
#str(snotel_874) # check the date, usually a character.  

snotel_874$Date <- as.Date(snotel_874$date) #change date from character to date format, capitalize to work with Water year functon from NWIS.

#THIS WILL CHANGE FOR EACH STATION
snotel_874_clean <- snotel_874 %>% # filter for the timeframe
  filter(Date >= "1979-10-01" & Date <= "2022-09-30") %>%
  #filter(temperature_mean >= -30 & temperature_mean <= 20) %>% # removing outliers   
  addWaterYear() %>% 
  mutate(daymonth = format(as.Date(Date), "%d-%m")) %>% 
  na.omit()

#adding water day using difftime (SUPER COOL. example from [this](https://stackoverflow.com/questions/48123049/create-day-index-based-on-water-year))

snotel_874_clean <- snotel_874_clean %>% 
  group_by(waterYear)%>% 
  mutate(waterDay = (as.integer(difftime(Date, ymd(paste0(waterYear - 1 ,'-09-30')), units = "days"))))
# Check for outliers

ggplot(snotel_874_clean, aes(x = Date, y = temperature_mean)) +
  geom_point() + #lwd = 2) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('Daily temperature (°C)') + 
  xlab('Date')

snotel_874_clean <- snotel_874_clean %>% 
  mutate(temp_diff = abs(temperature_min - temperature_max)) %>% 
  filter(temperature_mean > -40) %>% 
  filter(temperature_mean < 25)
ggplot(snotel_874_clean, aes(x = Date, y = temp_diff)) + 
  geom_point() + #lwd = 2) +
  theme_few() +
  #geom_smooth(method = "lm", se=FALSE) +
  ylab('Daily temperature varience (°C)') + 
  xlab('Date')

Per Steven’s advice: :If there are more than 15 missing days, then…remove that year”

# filtering for temperature anomalies
#snotel_874_cull_count <- snotel_874_clean %>% 
#  filter(temperature_min > -40) %>% 
#  count(waterYear)

#snotel_874_cull_count

# filtering for too few observations in a year
snotel_874_cull_count_days <- snotel_874_clean %>% 
  group_by(waterYear) %>% 
  count(waterYear) %>% 
  filter(n < 350)

snotel_874_cull_count_days
## # A tibble: 11 x 2
## # Groups:   waterYear [11]
##    waterYear     n
##        <dbl> <int>
##  1      1990   295
##  2      1994   313
##  3      2003   311
##  4      2006   340
##  5      2007   340
##  6      2008   315
##  7      2009   320
##  8      2010   303
##  9      2013   304
## 10      2016   338
## 11      2017   314

1990, 1994, 2003, 2006, 2007, 2008, 2009, 2010, 2013, 2016, 2017 need to be culled.

snotel_874_clean_culled <- snotel_874_clean %>% 
  filter(waterYear != "1990" & waterYear != "1994" & waterYear != "2003" & waterYear != "2006" & waterYear != "2007" & waterYear != "2008" & waterYear != "2009" & waterYear != "2010" & waterYear != "2013" & waterYear != "2016" & waterYear != "2017") #%>% 
  #filter(temperature_mean > -49)

ggplot(snotel_874_clean_culled, aes(x = Date, y = temp_diff)) + 
  geom_point() + #lwd = 2) +
  theme_few() +
  #geom_smooth(method = "lm", se=FALSE) +
  ylab('Daily temperature varience (°C)') + 
  xlab('Date')

ggplot(snotel_874_clean_culled, aes(x = Date, y = temperature_mean)) + 
  geom_point() + #lwd = 2) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('Daily temperature (°C)') + 
  xlab('Date')

temp_874_xts <- xts(snotel_874_clean_culled$temperature_mean, order.by = snotel_874_clean_culled$Date)

dygraph(temp_874_xts) %>%
  dyAxis("y", label = "Daily mean temperature (°C)") 
#snotel_874_clean_culled <- snotel_874_clean_culled %>% 
#  filter(temperature_mean < 19.3)

temp_874_xts <- xts(snotel_874_clean_culled$temperature_mean, order.by = snotel_874_clean_culled$Date)

dygraph(temp_874_xts) %>%
  dyAxis("y", label = "Daily mean temperature (°C)") 

Wolf Creek Summit 874

Morrisey 7/12/2004

snotel_874_adjusted <- snotel_874_clean_culled %>%
  mutate(temp_ad = if_else(Date < "2004-07-12", ((5.3*10^(-7))*(temperature_mean^(4))+(3.72*10^(-5))*(temperature_mean^(3))-(2.16*10^(-3))*(temperature_mean^(2))-(7.32*10^(-2))*(temperature_mean)+1.37)+temperature_mean, temperature_mean))

Non-corrected

874 Detrended

#using the clean culled df:

#average water year temperature

yearly_wy_aver_874 <- snotel_874_adjusted %>% 
  group_by(waterYear) %>% 
  mutate(aver_ann_temp = mean(temperature_mean))

#Average temperature by day for all water years:

daily_wy_aver_874 <- yearly_wy_aver_874 %>% 
  group_by(daymonth) %>% 
  mutate(aver_day_temp = mean(aver_ann_temp))

#average mean temperature by day for the period of record:

daily_wy_aver_874 <- daily_wy_aver_874 %>% 
  group_by(daymonth) %>% 
  mutate(all_ave_temp = mean(daily_wy_aver_874$aver_day_temp))

# try to show all years as means. 
daily_wy_aver2_874 <-daily_wy_aver_874 %>% 
  group_by(waterDay) %>%
  mutate(date_temp = mean(temperature_mean))
  

daily_wy_aver2_874$date_temp <- signif(daily_wy_aver2_874$date_temp,3) #reduce the sig figs


ggplot(daily_wy_aver2_874, aes(x = waterDay, y = date_temp))+
  geom_line(size= 0.7) +
  theme_few() +
  ylab('Average Daily temperature (°C)') + 
  xlab('Day of water year')

874 SD

standard_dev_874 <- daily_wy_aver_874 %>% 
  group_by(waterYear) %>% 
  mutate(residual = (all_ave_temp-aver_ann_temp)+temperature_mean-aver_day_temp) %>% 
  mutate(deviation = abs(residual-lag(residual)))

standard_dev_all_874 <- standard_dev_874 %>% 
  group_by(waterYear) %>% 
  mutate(nmbr = n())

standard_dev_all_874 <- standard_dev_all_874 %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)

standard_dev_all_874 %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1987 7.854854
1988 8.380441
1989 8.376871
1991 7.952272
1992 7.274045
1993 7.924599
1995 7.536845
1996 8.020204
1997 8.005351
1998 8.406529
1999 7.057906
2000 8.042917
2001 8.360075
2002 8.824249
2004 8.065839
2005 7.482529
2011 8.051681
2012 7.789860
2014 7.447867
2015 6.928269
2018 7.223986
2019 7.800112
2020 7.863897
2021 8.007803
2022 7.236522
ggplot(standard_dev_all_874, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Non-corrected standard deviation of SNOTEL 874 average temperatures for water years 2005-2021

MK & SS for 874 (non-corrected)

sd_mk_874 <- mk.test(standard_dev_all_874$sd_2)
print(sd_mk_874)
## 
##  Mann-Kendall trend test
## 
## data:  standard_dev_all_874$sd_2
## z = -1.4247, n = 25, p-value = 0.1543
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##            S         varS          tau 
##  -62.0000000 1833.3333333   -0.2066667
sd_sens_874 <- sens.slope(standard_dev_all_874$sd_2)
print(sd_sens_874)
## 
##  Sen's slope
## 
## data:  standard_dev_all_874$sd_2
## z = -1.4247, n = 25, p-value = 0.1543
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.046813576  0.005791174
## sample estimates:
## Sen's slope 
## -0.01681136

Corrected

874 Detrended (corrected)

#using the clean culled df:
#average water year temperature
yearly_wy_aver_874_ad <- snotel_874_adjusted %>% 
  group_by(waterYear) %>% 
  mutate(aver_ann_temp_ad = mean(temp_ad))
#Average temperature by day for all water years:
daily_wy_aver_874_ad <- yearly_wy_aver_874_ad %>% 
  group_by(daymonth) %>% 
  mutate(aver_day_temp_ad = mean(aver_ann_temp_ad))
#average mean temperature by day for the period of record:
daily_wy_aver_874_ad <- daily_wy_aver_874_ad %>% 
  group_by(daymonth) %>% 
  mutate(all_ave_temp_ad = mean(daily_wy_aver_874_ad$aver_day_temp_ad))
# try to show all years as means. 
daily_wy_aver2_874_ad <-daily_wy_aver_874_ad %>% 
  group_by(waterDay) %>%
  mutate(date_temp_ad = mean(temp_ad))
  
daily_wy_aver2_874_ad$date_temp_ad <- signif(daily_wy_aver2_874_ad$date_temp_ad,3) #reduce the sig figs
ggplot(daily_wy_aver2_874_ad, aes(x = waterDay, y = date_temp_ad))+
  geom_line(size= 0.7) +
  theme_few() +
  ylab('Average Daily temperature (°C)') + 
  xlab('Day of water year')

874 SS (corrected)

standard_dev_874_ad <- daily_wy_aver_874_ad %>% 
  group_by(waterYear) %>% 
  #filter(waterYear >= 1987 & waterYear <= 2021) %>% 
  mutate(residual = (all_ave_temp_ad-aver_ann_temp_ad)+temp_ad-aver_day_temp_ad) %>% 
  mutate(deviation = abs(residual-lag(residual)))
standard_dev_all_874_ad <- standard_dev_874_ad %>% 
  group_by(waterYear) %>% 
  mutate(nmbr = n())
standard_dev_all_874_ad <- standard_dev_all_874_ad %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)
standard_dev_all_874_ad %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1987 7.327962
1988 7.851838
1989 7.848099
1991 7.458480
1992 6.775174
1993 7.395057
1995 7.010946
1996 7.470539
1997 7.481361
1998 7.826754
1999 6.568878
2000 7.465159
2001 7.779500
2002 8.206390
2004 7.444487
2005 7.482090
2011 8.052315
2012 7.790524
2014 7.447936
2015 6.928554
2018 7.224892
2019 7.800202
2020 7.864350
2021 8.008044
2022 7.236992
ggplot(standard_dev_all_874_ad, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Morrisey-corrected standard deviation of SNOTEL 874 average temperatures for water years 1986-2021

MK & SS 874 (corrected)

sd_mk_874_ad <- mk.test(standard_dev_all_874_ad$sd_2)
print(sd_mk_874_ad)
## 
##  Mann-Kendall trend test
## 
## data:  standard_dev_all_874_ad$sd_2
## z = 0.81742, n = 25, p-value = 0.4137
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##        S     varS      tau 
##   36.000 1833.333    0.120
sd_sens_874_ad <- sens.slope(standard_dev_all_874_ad$sd_2)
print(sd_sens_874_ad)
## 
##  Sen's slope
## 
## data:  standard_dev_all_874_ad$sd_2
## z = 0.81742, n = 25, p-value = 0.4137
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.006890724  0.033504267
## sample estimates:
## Sen's slope 
## 0.006882736

Figure captions are not correct.

Summer and Winter SD NOT-CORRECTED

Summer

summer_standard_dev_all_874 <- standard_dev_874 %>%
  filter(waterDay >= 244 & waterDay <= 335) %>%
  group_by(waterYear) %>% 
  mutate(nmbr = n())

summer_standard_dev_all_874 <- summer_standard_dev_all_874 %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)

summer_standard_dev_all_874 %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1987 2.301386
1988 2.585726
1989 3.004368
1991 2.670905
1992 2.884099
1993 3.118708
1995 3.418628
1996 2.231442
1997 2.426972
1998 3.172632
1999 2.579648
2000 1.937835
2001 2.390252
2002 2.287826
2004 2.301057
2005 3.018852
2011 1.966234
2012 1.692489
2014 1.964946
2015 2.358728
2018 2.048511
2019 2.420984
2020 2.369083
2021 2.450898
2022 2.292576
ggplot(summer_standard_dev_all_874, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Non-corrected standard deviation of SNOTEL 874 average summer temperatures for water years 2005-2021

summer MK & SS for 874 (non-corrected)

summer_sd_mk_874 <- mk.test(summer_standard_dev_all_874$sd_2)
print(summer_sd_mk_874)
## 
##  Mann-Kendall trend test
## 
## data:  summer_standard_dev_all_874$sd_2
## z = -1.8918, n = 25, p-value = 0.05852
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##            S         varS          tau 
##  -82.0000000 1833.3333333   -0.2733333
summer_sd_sens_874 <- sens.slope(summer_standard_dev_all_874$sd_2)
print(summer_sd_sens_874)
## 
##  Sen's slope
## 
## data:  summer_standard_dev_all_874$sd_2
## z = -1.8918, n = 25, p-value = 0.05852
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.051900496  0.001114139
## sample estimates:
## Sen's slope 
##  -0.0235135

Winter

winter_standard_dev_all_874 <- standard_dev_874 %>%
  filter(waterDay >= 32 & waterDay <= 182) %>%
  group_by(waterYear) %>% 
  mutate(nmbr = n())

winter_standard_dev_all_874 <- winter_standard_dev_all_874 %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)

winter_standard_dev_all_874 %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1987 4.061936
1988 4.832543
1989 5.451625
1991 4.691108
1992 3.473366
1993 3.766941
1995 3.954827
1996 4.732658
1997 4.845022
1998 4.074815
1999 4.075788
2000 4.927227
2001 3.797701
2002 4.992024
2004 5.237861
2005 3.970113
2011 5.050437
2012 4.286693
2014 4.030299
2015 4.576167
2018 4.016512
2019 3.833885
2020 4.088284
2021 4.399188
2022 4.638982
ggplot(winter_standard_dev_all_874, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Non-corrected standard deviation of SNOTEL 874 average winter temperatures for water years 2005-2021

winter MK & SS for 874 (non-corrected)

winter_sd_mk_874 <- mk.test(winter_standard_dev_all_874$sd_2)
print(winter_sd_mk_874)
## 
##  Mann-Kendall trend test
## 
## data:  winter_standard_dev_all_874$sd_2
## z = 0.11677, n = 25, p-value = 0.907
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##        S     varS      tau 
##    6.000 1833.333    0.020
winter_sd_sens_874 <- sens.slope(winter_standard_dev_all_874$sd_2)
print(winter_sd_sens_874)
## 
##  Sen's slope
## 
## data:  winter_standard_dev_all_874$sd_2
## z = 0.11677, n = 25, p-value = 0.907
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.03693833  0.02951488
## sample estimates:
## Sen's slope 
## 0.001119478

Summer and Winter SD CORRECTED

Summer

summer_standard_dev_all_874_ad <- standard_dev_874_ad %>% 
  filter(waterDay >= 244 & waterDay <= 335) %>%
  group_by(waterYear) %>% 
  mutate(nmbr = n())
summer_standard_dev_all_874_ad <- summer_standard_dev_all_874_ad %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)
summer_standard_dev_all_874_ad %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1987 2.067990
1988 2.333310
1989 2.697472
1991 2.412870
1992 2.603861
1993 2.815957
1995 3.077053
1996 2.001191
1997 2.188199
1998 2.857796
1999 2.330436
2000 1.735144
2001 2.153284
2002 2.049339
2004 2.145615
2005 3.017410
2011 1.967414
2012 1.690995
2014 1.962954
2015 2.357646
2018 2.047435
2019 2.420713
2020 2.368572
2021 2.450683
2022 2.292765
ggplot(summer_standard_dev_all_874_ad, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Morrisey-corrected standard deviation of SNOTEL 874 average summer temperatures for water years 1986-2021

summer MK & SS 874 (corrected)

summer_sd_mk_874_ad <- mk.test(summer_standard_dev_all_874_ad$sd_2)
print(summer_sd_mk_874_ad)
## 
##  Mann-Kendall trend test
## 
## data:  summer_standard_dev_all_874_ad$sd_2
## z = -0.81742, n = 25, p-value = 0.4137
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##        S     varS      tau 
##  -36.000 1833.333   -0.120
summer_sd_sens_874_ad <- sens.slope(summer_standard_dev_all_874_ad$sd_2)
print(summer_sd_sens_874_ad)
## 
##  Sen's slope
## 
## data:  summer_standard_dev_all_874_ad$sd_2
## z = -0.81742, n = 25, p-value = 0.4137
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.03172149  0.01524502
## sample estimates:
##  Sen's slope 
## -0.007710063

Winter

winter_standard_dev_all_874_ad <- standard_dev_874_ad %>% 
  filter(waterDay >= 32 & waterDay <= 182) %>%
  group_by(waterYear) %>% 
  mutate(nmbr = n())
winter_standard_dev_all_874_ad <- winter_standard_dev_all_874_ad %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)
winter_standard_dev_all_874_ad %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1987 3.930208
1988 4.700087
1989 5.293992
1991 4.570232
1992 3.352405
1993 3.649435
1995 3.820087
1996 4.575167
1997 4.673789
1998 3.930004
1999 3.919844
2000 4.703588
2001 3.676065
2002 4.802910
2004 5.055491
2005 3.969583
2011 5.051431
2012 4.288012
2014 4.029693
2015 4.575844
2018 4.016674
2019 3.833270
2020 4.087497
2021 4.399418
2022 4.638674
ggplot(winter_standard_dev_all_874_ad, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Morrisey-corrected standard deviation of SNOTEL 874 average winter temperatures for water years 1986-2021

winter MK & SS 874 (corrected)

winter_sd_mk_874_ad <- mk.test(winter_standard_dev_all_874_ad$sd_2)
print(winter_sd_mk_874_ad)
## 
##  Mann-Kendall trend test
## 
## data:  winter_standard_dev_all_874_ad$sd_2
## z = 0.58387, n = 25, p-value = 0.5593
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##            S         varS          tau 
## 2.600000e+01 1.833333e+03 8.666667e-02
winter_sd_sens_874_ad <- sens.slope(winter_standard_dev_all_874_ad$sd_2)
print(winter_sd_sens_874_ad)
## 
##  Sen's slope
## 
## data:  winter_standard_dev_all_874_ad$sd_2
## z = 0.58387, n = 25, p-value = 0.5593
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.02540713  0.03689025
## sample estimates:
## Sen's slope 
## 0.007514331

Spring and Fall SD NOT-CORRECTED

Spring

spring_standard_dev_all_874 <- standard_dev_874 %>%
  filter(waterDay >= 183 & waterDay <= 243) %>%
  group_by(waterYear) %>% 
  mutate(nmbr = n())

spring_standard_dev_all_874 <- spring_standard_dev_all_874 %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)

spring_standard_dev_all_874 %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1987 3.503794
1988 4.583246
1989 3.878690
1991 4.652587
1992 3.198329
1993 4.127254
1995 3.726544
1996 5.084603
1997 5.143491
1998 5.172576
1999 5.078257
2000 4.933461
2001 5.046062
2002 3.787759
2004 4.180013
2005 4.553687
2011 4.183998
2012 3.980530
2014 4.769698
2015 3.077445
2018 4.146672
2019 3.484671
2020 4.074214
2021 3.680975
2022 4.263166
ggplot(spring_standard_dev_all_874, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Non-corrected standard deviation of SNOTEL 874 average spring temperatures for water years 2005-2021

spring MK & SS for 874 (non-corrected)

spring_sd_mk_874 <- mk.test(spring_standard_dev_all_874$sd_2)
print(spring_sd_mk_874)
## 
##  Mann-Kendall trend test
## 
## data:  spring_standard_dev_all_874$sd_2
## z = -0.81742, n = 25, p-value = 0.4137
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##        S     varS      tau 
##  -36.000 1833.333   -0.120
spring_sd_sens_874 <- sens.slope(spring_standard_dev_all_874$sd_2)
print(spring_sd_sens_874)
## 
##  Sen's slope
## 
## data:  spring_standard_dev_all_874$sd_2
## z = -0.81742, n = 25, p-value = 0.4137
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.06062732  0.02804329
## sample estimates:
## Sen's slope 
## -0.01721112

Fall

Fall is split each water year in the middle of the season. This analysis splits the fall season between the preceding water year and the subsequent water year.

fall_standard_dev_all_874 <- standard_dev_874 %>%
  filter(waterDay >= 336 | waterDay <= 31) %>% 
  group_by(waterYear) %>% 
  mutate(nmbr = n())

fall_standard_dev_all_874 <- fall_standard_dev_all_874 %>% 
  #group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)

fall_standard_dev_all_874 %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1987 3.850321
1988 3.445826
1989 2.763051
1991 3.701213
1992 4.783121
1993 3.594848
1995 4.959015
1996 4.048618
1997 5.968543
1998 5.421911
1999 3.836368
2000 4.086141
2001 4.774502
2002 3.609430
2004 3.728847
2005 4.435655
2011 4.161632
2012 4.727413
2014 5.286588
2015 3.310276
2018 3.751505
2019 4.673047
2020 6.100409
2021 4.515773
2022 4.922570
ggplot(fall_standard_dev_all_874, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Non-corrected standard deviation of SNOTEL 874 average fall temperatures for water years 2005-2021. Note that the season is split by the water year.

fall MK & SS for 874 (non-corrected)

fall_sd_mk_874 <- mk.test(fall_standard_dev_all_874$sd_2)
print(fall_sd_mk_874)
## 
##  Mann-Kendall trend test
## 
## data:  fall_standard_dev_all_874$sd_2
## z = 1.7049, n = 25, p-value = 0.08821
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##            S         varS          tau 
##   74.0000000 1833.3333333    0.2466667
fall_sd_sens_874 <- sens.slope(fall_standard_dev_all_874$sd_2)
print(fall_sd_sens_874)
## 
##  Sen's slope
## 
## data:  fall_standard_dev_all_874$sd_2
## z = 1.7049, n = 25, p-value = 0.08821
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.006474919  0.086851214
## sample estimates:
## Sen's slope 
##   0.0461987

Spring and Fall SD CORRECTED

Spring

spring_standard_dev_all_874_ad <- standard_dev_874_ad %>% 
  filter(waterDay >= 183 & waterDay <= 243) %>%
  group_by(waterYear) %>% 
  mutate(nmbr = n())
spring_standard_dev_all_874_ad <- spring_standard_dev_all_874_ad %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)
spring_standard_dev_all_874_ad %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1987 3.268415
1988 4.259529
1989 3.558915
1991 4.351604
1992 2.944997
1993 3.824362
1995 3.487503
1996 4.691909
1997 4.808979
1998 4.812915
1999 4.753695
2000 4.530724
2001 4.661604
2002 3.458439
2004 3.855217
2005 4.554551
2011 4.184875
2012 3.980939
2014 4.770122
2015 3.078730
2018 4.148562
2019 3.483188
2020 4.076084
2021 3.683517
2022 4.263216
ggplot(spring_standard_dev_all_874_ad, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Morrisey-corrected standard deviation of SNOTEL 874 average spring temperatures for water years 1986-2021

spring MK & SS 874 (corrected)

spring_sd_mk_874_ad <- mk.test(spring_standard_dev_all_874_ad$sd_2)
print(spring_sd_mk_874_ad)
## 
##  Mann-Kendall trend test
## 
## data:  spring_standard_dev_all_874_ad$sd_2
## z = 0.023355, n = 25, p-value = 0.9814
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##            S         varS          tau 
## 2.000000e+00 1.833333e+03 6.666667e-03
spring_sd_sens_874_ad <- sens.slope(spring_standard_dev_all_874_ad$sd_2)
print(spring_sd_sens_874_ad)
## 
##  Sen's slope
## 
## data:  spring_standard_dev_all_874_ad$sd_2
## z = 0.023355, n = 25, p-value = 0.9814
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  -0.03881703  0.03886942
## sample estimates:
## Sen's slope 
## 0.001106798

Fall

fall_standard_dev_all_874_ad <- standard_dev_874_ad %>% 
  filter(waterDay >= 336 | waterDay <= 31) %>%
  group_by(waterYear) %>% 
  mutate(nmbr = n())
fall_standard_dev_all_874_ad <- fall_standard_dev_all_874_ad %>% 
  group_by(waterYear) %>% 
  mutate(resid_mean = mean(residual)) %>%
  mutate(sd_1 = residual-resid_mean) %>% 
  mutate(sd_2 = (((sum((sd_1)^2))/((nmbr-1))))^(0.5)) %>%
  distinct(sd_2, .keep_all = TRUE) %>% 
   select(waterYear, sd_2)
fall_standard_dev_all_874_ad %>% 
  kable(.,'html') %>%
  kable_styling() %>%
  scroll_box(width='250px',height='500px')
waterYear sd_2
1987 3.551381
1988 3.140421
1989 2.512434
1991 3.408614
1992 4.440021
1993 3.304192
1995 4.542029
1996 3.710193
1997 5.530279
1998 4.996627
1999 3.527576
2000 3.724093
2001 4.371674
2002 3.292284
2004 3.472238
2005 4.436454
2011 4.161513
2012 4.726109
2014 5.287766
2015 3.312654
2018 3.752238
2019 4.673643
2020 6.100948
2021 4.513662
2022 4.924006
ggplot(fall_standard_dev_all_874_ad, aes(x = waterYear, y = sd_2))+
  geom_line(size= 0.7) +
  theme_few() +
  geom_smooth(method = "lm", se=FALSE) +
  ylab('SD') + 
  xlab('Water year')

Morrisey-corrected standard deviation of SNOTEL 874 average fall temperatures for water years 1986-2021. Note that the fall season is split by the water year.

fall MK & SS 874 (corrected)

fall_sd_mk_874_ad <- mk.test(fall_standard_dev_all_874_ad$sd_2)
print(fall_sd_mk_874_ad)
## 
##  Mann-Kendall trend test
## 
## data:  fall_standard_dev_all_874_ad$sd_2
## z = 2.499, n = 25, p-value = 0.01246
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##        S     varS      tau 
##  108.000 1833.333    0.360
fall_sd_sens_874_ad <- sens.slope(fall_standard_dev_all_874_ad$sd_2)
print(fall_sd_sens_874_ad)
## 
##  Sen's slope
## 
## data:  fall_standard_dev_all_874_ad$sd_2
## z = 2.499, n = 25, p-value = 0.01246
## alternative hypothesis: true z is not equal to 0
## 95 percent confidence interval:
##  0.01265523 0.10242610
## sample estimates:
## Sen's slope 
##  0.06134895

(getting git workflow errors…)